frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
21.89k stars 7.34k forks source link

Validations for Custom field option value for Data type fields #28637

Closed mohsinalimat closed 2 years ago

mohsinalimat commented 2 years ago

After upgrading from v12 to v13 the below error comes while bench --site test.site migrate --skip-failing.

Migrating test.site Executing erpnext.patches.v12_0.add_eway_bill_in_delivery_note in test.site (_1234567890) Failed to execute patch Executing erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020 in test.site (_1234567890) Failed to execute patch Executing erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation in test.site (_1234567890) Failed to execute patch Executing erpnext.patches.v12_0.add_gst_category_in_delivery_note in test.site (_1234567890) Failed to execute patch

ankush commented 2 years ago

Can't do much without tracebacks for patch failure. can you share full tracebacks?

mohsinalimat commented 2 years ago

log of Executing erpnext.patches.v12_0.add_eway_bill_in_delivery_note

Migrating site1.local Executing erpnext.patches.v12_0.add_eway_bill_in_delivery_note in site1.local (_1234567890) Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 104, in main() File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 19, in main click.Group(commands=commands)(prog_name='bench') File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 829, in call return self.main(args, kwargs) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke return callback(args, kwargs) File "/home/frappe/frappe-bench/env/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func return f(get_current_context(), *args, *kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/init.py", line 27, in _func ret = f(frappe._dict(ctx.obj), args, kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 306, in migrate migrate( File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 67, in migrate frappe.modules.patch_handler.run_all(skip_failing) File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 41, in run_all run_patch(patch) File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 30, in run_patch if not run_single(patchmodule = patch): File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 71, in run_single return execute_patch(patchmodule, method, methodargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 91, in execute_patch frappe.get_attr(patchmodule.split()[0] + ".execute")() File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v12_0/add_eway_bill_in_delivery_note.py", line 11, in execute create_custom_field('Delivery Note', { File "/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py", line 142, in create_custom_field custom_field.insert() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 268, in insert self.run_post_save_methods() File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1001, in run_post_save_methods self.run_method("on_update") File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 860, in run_method out = Document.hook(fn)(self, *args, kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1158, in composer return composed(self, method, *args, *kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1141, in runner add_to_return_value(self, fn(self, args, kwargs)) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 854, in fn = lambda self, *args, *kwargs: getattr(self, method)(args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py", line 76, in on_update validate_fields_for_doctype(self.dt) File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 751, in validate_fields_for_doctype validate_fields(meta) File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 1062, in validate_fields validate_data_field_type(d) File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 1016, in validate_data_field_type frappe.msgprint(text_str + df_options_str, title="Invalid Data Field", raise_exception=True) File "/home/frappe/frappe-bench/apps/frappe/frappe/init.py", line 418, in msgprint _raise_exception() File "/home/frappe/frappe-bench/apps/frappe/frappe/init.py", line 374, in _raise_exception raise ValidationError(msg) frappe.exceptions.ValidationError: Issued By is an invalid Data field.

Only Options allowed for Data field are:

ankush commented 2 years ago

You've added "Issued By" in the option of some custom field or maybe it was added before this validation was put in place.

Removing that from "Option" should fix it.

mohsinalimat commented 2 years ago

Old version

ERPNext: v12.16.2 (version-12)

Frappe Framework: v12.13.0 (version-12)

and migrate to v13 latest above error comes.

mohsinalimat commented 2 years ago

Old version

ERPNext: v12.16.2 (version-12)

Frappe Framework: v12.13.0 (version-12)

and migrate to v13 latest above error comes.

@ankush please see this message.

ankush commented 2 years ago

I saw, check my previous message. You'll most likely have to find which fields have "Issued By" set as option (can be found using filters). Then remove that option.

ankush commented 2 years ago

There was a patch added to fix this exact same thing.

https://github.com/frappe/erpnext/pull/27200

Maybe that's already executed on your site or maybe it needs to be reordered.

mohsinalimat commented 2 years ago

You've added "Issued By" in the option of some custom field or maybe it was added before this validation was put in place.

Removing that from "Option" should fix it.

I don't know how to solve this.

Can you please guide me in video or screenshots or other way?

ankush commented 2 years ago

Potential solution:

https://github.com/frappe/erpnext/pull/27200

The patch for custom field option correction seems to be executing in an incorrect order. This patch should be higher up execution order (near start of v13 patches)

Mostly just reordering the patch execution and re-executing it should work.

ankush commented 2 years ago
  I don't know how to solve this.

Can you please guide me in video or screenshots or another way?

go to Custom Field list and find which Data field has Option equal to Issued By. You can find them with filters.

Alternatively if you can execute the patch manually, then execute the patch I linked above.

mohsinalimat commented 2 years ago
  I don't know how to solve this.

Can you please guide me in video or screenshots or another way?

go to Custom Field list and find which Data field has Option equal to Issued By. You can find them with filters.

Alternatively if you can execute the patch manually, then execute the patch I linked above.

Screenshot 2021-12-10 at 2 25 38 PM

ankush commented 2 years ago

Go to delivery note > customize form and erase the "Option" value. Link fields can have options, data fields can't.

mohsinalimat commented 2 years ago

Go to delivery note > customize form and erase the "Option" value. Link fields can have options, data fields can't.

Now working perfectly.

Thanks @ankush You are a genius.