Error while updating v8 to v9 on patch v8_7: End date must be greater than start date

Hi, run across this error while updating using bench update:

Executing erpnext.patches.v8_7.make_subscription_from_recurring_data in site1.local (1bd3e0294da19198)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, 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/ubuntu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/ubuntu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/ubuntu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/ubuntu/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/ubuntu/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/ubuntu/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/ubuntu/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/ubuntu/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/ubuntu/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/commands/site.py", line 222, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/migrate.py", line 31, in migrate
    frappe.modules.patch_handler.run_all()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all
    if not run_single(patchmodule = patch):
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/patches/v8_7/make_subscription_from_recurring_data.py", line 27, in execute
    make_subscription(doctype, data, date_field)
  File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/patches/v8_7/make_subscription_from_recurring_data.py", line 55, in make_subscription
    }).insert(ignore_permissions=True)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 218, in insert
    self.run_before_save_methods()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 859, in run_before_save_methods
    self.run_method("validate")
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 755, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 1024, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 1007, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/model/document.py", line 749, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/accounts/doctype/subscription/subscription.py", line 21, in validate
    self.validate_dates()
  File "/home/ubuntu/frappe-bench/apps/erpnext/erpnext/accounts/doctype/subscription/subscription.py", line 54, in validate_dates
    frappe.throw(_("End date must be greater than start date"))
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 323, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 309, in msgprint
    _raise_exception()
  File "/home/ubuntu/frappe-bench/apps/frappe/frappe/__init__.py", line 282, in _raise_exception
    raise raise_exception(encode(msg))
frappe.exceptions.ValidationError: End date must be greater than start date

Already tried the following command and still same error:
bench --site site1.local reload-doc accounts doctype subscription
bench migrate

Based on this:

This person has a similar issue and got it to worked by manually adding a column in db but I’m not sure it’s the right way:

And this one here stated that the issue has been fixed:

Stuck here, any ideas? Much appreciated as our company is relying on this update to work, thanks!

Hi

I have same error because my tabSales Order table have transaction_date >= end_date;

run script to find have record have transaction_date >= end_date

SELECT name, transaction_date, end_date, from_date, to_date FROM `tabSales Order` 
WHERE end_date IS NOT NULL AND transaction_date >= end_date;

update end_date=from_date

UPDATE `tabSales Order` SET `end_date`=`from_date` WHERE transaction_date >= end_date;

Hope help you.

Hi,

Still not working, already manually changed the end_date > transaction_date. Even added an extra year to make sure it works.

Am I missing something? Thanks.

You run this script and result return records or empty?

Hi

Run all these script check these tables. If have record must to update end_date >= transaction_date.

SELECT name, transaction_date, end_date, from_date, to_date FROM `tabSales Order` 
WHERE end_date IS NOT NULL AND transaction_date >= end_date;

SELECT name, transaction_date, end_date, from_date, to_date FROM `tabPurchase Order` 
WHERE end_date IS NOT NULL AND transaction_date >= end_date;

SELECT name, posting_date, end_date, from_date, to_date FROM `tabSales Invoice` 
WHERE end_date IS NOT NULL AND posting_date >= end_date;

SELECT name, posting_date, end_date, from_date, to_date FROM `tabPurchase Invoice` 
WHERE end_date IS NOT NULL AND posting_date >= end_date;

Don’t forget to run on the Subscription table too. That is where the error is coming from.

Awesome, just great.

It turns out the problem was in tabSales Invoice table. Update the columns accordingly, do bench update again and it works like a charm.

Still strange though how the data got mixed up in the first place.

Thanks @vinhnguyent090 and @James_Robertson for the help!

3 Likes