[develop] Job Card data model job_card.json exists but tabJob Card not found in database?

With regard to this test error:

(env) frappe@ubuntu:~/frappe-bench$ bench run-tests --doctype ‘Journal Entry’
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py”, line 25, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.py”, line 406, in run_tests
ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)
File “/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py”, line 66, in main
ret = run_tests_for_doctype(doctype, verbose, tests, force, profile)
File “/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py”, line 144, in run_tests_for_doctype
make_test_records(doctype, verbose=verbose, force=force)
File “/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py”, line 258, in make_test_records
make_test_records_for_doctype(options, verbose, force)
File “/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py”, line 306, in make_test_records_for_doctype
frappe.local.test_objects[doctype] += make_test_objects(doctype, test_module.test_records, verbose, force)
File “/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py”, line 357, in make_test_objects
d.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 222, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 877, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 773, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1049, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1032, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 767, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 63, in validate
self.set_job_card_data()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/stock_entry/stock_entry.py”, line 114, in set_job_card_data
if self.job_card and not self.work_order:
AttributeError: ‘StockEntry’ object has no attribute ‘job_card’

This Job Card model spec suggests tabJob Card should exist in the database, but there is no such table to be found!?

My question is must the tabJob Card be explicitly created and executed in SQL?

Seems like the field job_card wasn’t loaded in Stock Entry.

Try going into bench --site site_name console and run

frappe.reload_doc('stock', 'doctype', 'Stock Entry', force=True)
frappe.db.commit()

Exit from the console and try again.

1 Like

Wunderbar thanks for the learning that worked as expected!

what would have been the possiblity of this getting solved or worse break if bench migrate had been executed instead of your solution ? because my reaction to this query was hey you have JSON but not in DB so try bench migrate

Yes quite possibly migrate would have had the same result.

To my thinking Zarrar’s fix informs better what actually migrate does under the covers in the case of this problem?

edit: FWIW your migrate comment reminds me of my exercise here V8 update warning *json is missing

Big learning root13F and Zarrar - you two are too polite!

edit: That goes for @rmehta and @nabinhait too :slight_smile:

If I had simply run migrate to begin with, it seems I would not have had any error at all!!

(env) frappe@ubuntu:~/frappe-bench$ bench run-tests --doctype 'Journal Entry'
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.py", line 406, in run_tests
    ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 66, in main
    ret = run_tests_for_doctype(doctype, verbose, tests, force, profile)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 144, in run_tests_for_doctype
    make_test_records(doctype, verbose=verbose, force=force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 257, in make_test_records
    make_test_records(options, verbose, force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 257, in make_test_records
    make_test_records(options, verbose, force)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 251, in make_test_records
    for options in get_dependencies(doctype):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/test_runner.py", line 277, in get_dependencies
    link_fields.extend(frappe.get_meta(df.options).get_link_fields())
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 734, in get_meta
    return frappe.model.meta.get_meta(doctype, cached=cached)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 38, in get_meta
    meta = Meta(doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 85, in __init__
    super(Meta, self).__init__("DocType", doctype)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 104, in __init__
    self.load_from_db()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/meta.py", line 90, in load_from_db
    super(Meta, self).load_from_db()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 141, in load_from_db
    frappe.throw(_("{0} {1} not found").format(_(self.doctype), self.name), frappe.DoesNotExistError)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 339, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 325, in msgprint
    _raise_exception()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 298, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: DocType Job Card Item not found
(env) frappe@ubuntu:~/frappe-bench$ bench migrate
Migrating site1.local
Executing frappe.patches.v10_0.modify_smallest_currency_fraction in site1.local (1bd3e0294da19198)
Success: Done in 0.111s
Executing erpnext.patches.v8_7.sync_india_custom_fields in site1.local (1bd3e0294da19198)
Success: Done in 42.425s
Executing erpnext.patches.v11_0.refactor_erpnext_shopify #2018-09-07 in site1.local (1bd3e0294da19198)
Success: Done in 1.019s
Executing erpnext.patches.v11_0.add_expense_claim_default_account in site1.local (1bd3e0294da19198)
Success: Done in 1.808s
Executing execute:frappe.delete_doc("Page", "hub") in site1.local (1bd3e0294da19198)
Success: Done in 2.56s
Executing erpnext.patches.v11_0.reset_publish_in_hub_for_all_items in site1.local (1bd3e0294da19198)
Success: Done in 2.148s
Executing erpnext.patches.v11_0.update_hub_url # 2018-08-31  # 2018-09-03 in site1.local (1bd3e0294da19198)
Success: Done in 0.213s
Executing erpnext.patches.v10_0.set_discount_amount in site1.local (1bd3e0294da19198)
Success: Done in 23.381s
Executing erpnext.patches.v10_0.recalculate_gross_margin_for_project in site1.local (1bd3e0294da19198)
Success: Done in 1.175s
Executing erpnext.patches.v11_0.make_job_card in site1.local (1bd3e0294da19198)
Success: Done in 3.137s
Executing erpnext.patches.v11_0.redesign_healthcare_billing_work_flow in site1.local (1bd3e0294da19198)
Success: Done in 0.401s
Executing erpnext.patches.v10_0.delete_hub_documents # 12-08-2018 in site1.local (1bd3e0294da19198)
Success: Done in 1.827s
Executing erpnext.patches.v11_0.rename_healthcare_fields in site1.local (1bd3e0294da19198)
Success: Done in 15.748s
Updating DocTypes for frappe        : [========================================]
Updating DocTypes for erpnext       : [========================================]
Syncing help database...
(env) frappe@ubuntu:~/frappe-bench$ bench run-tests --doctype 'Journal Entry'
.........
----------------------------------------------------------------------
Ran 9 tests in 31.484s

OK
3 Likes

My bad, I kinda assumed this error prevailed after having done bench migrate. Should have recommended migrate first.

Anyway, this error can come even after bench migrate solely because the DocType may not have picked up latest changes from json - because of unchanged or back dated modified_date in json.

Sometimes, during rebase or so, it might happen that the modified_date in json does not get updated or so and in such case, the updated json wont be reflected which could lead to field not found or such error. In such scenario, if what I provided solves the issue, then one can update the modified_date in the json to today’s date and send in a pull request :+1:

2 Likes