# Buggy code
def mark_student_attendance(current_date):
    status = ["Present", "Absent"]
    for d in frappe.db.get_list(
        "Course Schedule",
        filters={"schedule_date": current_date},
        fields=("name", "student_group"),
    ):
        students = get_student_group_students(d.student_group)
        for stud in students:
            make_attendance_records(
                stud.student, stud.student_name, d.name, status[weighted_choice([9, 4])]
            )


# Traceback (frappe.exceptions.LinkValidationError)
➜  frappe-bench bench --site school.erpnext.dev execute erpnext.demo.demo.make --args Education
Complete Setup...
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 79, in <module>
main()
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 16, in main
click.Group(commands=commands)(prog_name='bench')
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/Users/rushabh/frappe/frappe-bench/env/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/commands/utils.py", line 110, in execute
ret = frappe.get_attr(method)(*args, **kwargs)
File "/Users/rushabh/frappe/frappe-bench/apps/erpnext/erpnext/demo/demo.py", line 32, in make
education.setup_data()
File "/Users/rushabh/frappe/frappe-bench/apps/erpnext/erpnext/demo/setup/education.py", line 12, in setup_data
make_masters()
File "/Users/rushabh/frappe/frappe-bench/apps/erpnext/erpnext/demo/setup/education.py", line 26, in make_masters
import_json("Program")
File "/Users/rushabh/frappe/frappe-bench/apps/erpnext/erpnext/demo/setup/setup_data.py", line 356, in import_json
doc.insert()
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 213, in insert
self._validate()
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 388, in _validate
self._validate_links()
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 630, in _validate_links
frappe.LinkValidationError)
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 302, in throw
msgprint(msg, raise_exception=exc, title=title, indicator='red')
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 295, in msgprint
_raise_exception()
File "/Users/rushabh/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 268, in _raise_exception
raise raise_exception, encode(msg)
frappe.exceptions.LinkValidationError: Could not find Row #1: Academic Term: Semester 1, Row #2: Academic Term: Semester 1, Row #3: Academic Term: Semester 2

# Fixed code
def mark_student_attendance(current_date):
    status = ["Present", "Absent"]
    for d in frappe.db.get_list("Student Group", filters={"group_based_on": "Batch"}):
        students = get_student_group_students(d.name)
        for stud in students:
            make_attendance_records(
                stud.student,
                stud.student_name,
                status[weighted_choice([9, 4])],
                None,
                d.name,
                current_date,
            )