Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent KeyError by checking report_filter existence (backport #43212) #43230

Merged

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Sep 16, 2024

Traceback
Frappe Support Issue:

Backport: version-15

Migrating aptener.frappe.cloud
Updating DocTypes for frappe        : [========================================] 100%
Updating DocTypes for erpnext       : [========================================] 100%
Updating DocTypes for ecommerce_integrations: [========================================] 100%
Updating DocTypes for email_delivery_service: [========================================] 100%
Updating DocTypes for erpnext_shipping: [========================================] 100%
Updating DocTypes for hrms          : [========================================] 100%
Updating DocTypes for insights      : [========================================] 100%
Updating DocTypes for posawesome    : [========================================] 100%
Updating DocTypes for hr_addon      : [========================================] 100%
Updating DocTypes for print_designer: [========================================] 100%
Updating DocTypes for builder       : [========================================] 100%
Updating DocTypes for sheets        : [========================================] 100%
Updating DocTypes for chat          : [========================================] 100%
Updating DocTypes for crm           : [========================================] 100%
Updating DocTypes for frappe_whatsapp: [========================================] 100%
Executing erpnext.patches.v15_0.update_invoice_remarks in aptener.frappe.cloud (_be52c281ffc78bb5)
Success: Done in 0.817s
Executing erpnext.patches.v14_0.update_reports_with_range in aptener.frappe.cloud (_be52c281ffc78bb5)

Traceback with variables (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
      mod_name = 'frappe.utils.bench_helper'
      alter_argv = True
      mod_spec = ModuleSpec(name='frappe.utils.bench_helper', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, origin='/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py')
      code = <code object <module> at 0xd85440, file "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 1>
      main_globals = {'__name__': '__main__', '__doc__': None, '__package__': 'frappe.utils', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, '__spec__': ModuleSpec(name='frappe.utils.bench_helper', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, origin='/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py'), '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py', '__cached__': '/home/frappe/frappe-bench/apps/frappe/frappe/utils/__pycache__/bench_helper.cpython-311.pyc', 'importlib': <module 'importlib' from '/usr/lib/python3.11/importlib/__init__.py'>, 'json': <module 'json' from '/usr/lib/python3.11/json/__init__.py'>, 'os': <module 'os' (frozen)>, 'traceback': <module 'traceback' from '/usr/lib/python3.11/traceback.py'>, 'warnings': <module 'warnings' from '/usr/lib/python3.11/warnings.py'>, 'Path': <class 'pathlib.Path'>, 'de...
  File "<frozen runpy>", line 88, in _run_code
      code = <code object <module> at 0xd85440, file "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 1>
      run_globals = {'__name__': '__main__', '__doc__': None, '__package__': 'frappe.utils', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, '__spec__': ModuleSpec(name='frappe.utils.bench_helper', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, origin='/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py'), '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py', '__cached__': '/home/frappe/frappe-bench/apps/frappe/frappe/utils/__pycache__/bench_helper.cpython-311.pyc', 'importlib': <module 'importlib' from '/usr/lib/python3.11/importlib/__init__.py'>, 'json': <module 'json' from '/usr/lib/python3.11/json/__init__.py'>, 'os': <module 'os' (frozen)>, 'traceback': <module 'traceback' from '/usr/lib/python3.11/traceback.py'>, 'warnings': <module 'warnings' from '/usr/lib/python3.11/warnings.py'>, 'Path': <class 'pathlib.Path'>, 'de...
      init_globals = None
      mod_name = '__main__'
      mod_spec = ModuleSpec(name='frappe.utils.bench_helper', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>, origin='/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py')
      pkg_name = 'frappe.utils'
      script_name = None
      loader = <_frozen_importlib_external.SourceFileLoader object at 0x7f64e5453490>
      fname = '/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py'
      cached = '/home/frappe/frappe-bench/apps/frappe/frappe/utils/__pycache__/bench_helper.cpython-311.pyc'
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
      ...skipped... 27 vars
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
      commands = {'frappe': <Group frappe>, 'get-frappe-commands': <Command get-frappe-commands>, 'get-frappe-help': <Command get-frappe-help>}
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
      self = <Group None>
      args = ()
      kwargs = {'prog_name': 'bench'}
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
      self = <Group None>
      args = ['frappe', '--site', 'aptener.frappe.cloud', 'migrate', '--skip-search-index']
      prog_name = 'bench'
      complete_var = None
      standalone_mode = True
      windows_expand_args = True
      extra = {}
      ctx = <click.core.Context object at 0x7f64e3ff9a10>
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
      self = <Group None>
      ctx = <click.core.Context object at 0x7f64e3ff9a10>
      _process_result = <function MultiCommand.invoke.<locals>._process_result at 0x7f64e4006980>
      args = ['migrate', '--skip-search-index']
      cmd_name = 'frappe'
      cmd = <Group frappe>
      sub_ctx = <click.core.Context object at 0x7f64e1373790>
      __class__ = <class 'click.core.MultiCommand'>
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
      self = <Group frappe>
      ctx = <click.core.Context object at 0x7f64e1373790>
      _process_result = <function MultiCommand.invoke.<locals>._process_result at 0x7f64e1366840>
      args = []
      cmd_name = 'migrate'
      cmd = <Command migrate>
      sub_ctx = <click.core.Context object at 0x7f64e13760d0>
      __class__ = <class 'click.core.MultiCommand'>
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
      self = <Command migrate>
      ctx = <click.core.Context object at 0x7f64e13760d0>
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
      _Context__self = <click.core.Context object at 0x7f64e13760d0>
      _Context__callback = <function migrate at 0x7f64e4068cc0>
      args = ()
      kwargs = {'skip_search_index': True, 'skip_failing': False}
      ctx = <click.core.Context object at 0x7f64e13760d0>
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
      args = ()
      kwargs = {'skip_search_index': True, 'skip_failing': False}
      f = <function migrate at 0x7f64e4068c20>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
      ctx = <click.core.Context object at 0x7f64e13760d0>
      args = ()
      kwargs = {'skip_search_index': True, 'skip_failing': False}
      profile = False
      f = <function migrate at 0x7f64e40689a0>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 619, in migrate
    ).run(site=site)
      context = {'sites': ['aptener.frappe.cloud'], 'force': False, 'verbose': False, 'profile': False}
      skip_failing = False
      skip_search_index = True
      activate_by_import = <module 'traceback_with_variables.activate_by_import' from '/home/frappe/frappe-bench/env/lib/python3.11/site-packages/traceback_with_variables/activate_by_import.py'>
      SiteMigration = <class 'frappe.migrate.SiteMigration'>
      site = 'aptener.frappe.cloud'
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 186, in run
    self.run_schema_updates()
      self = <frappe.migrate.SiteMigration object at 0x7f64de8e38d0>
      site = 'aptener.frappe.cloud'
      filelock = <function filelock at 0x7f64de1b0ae0>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 52, in wrapper
    raise e
      args = (<frappe.migrate.SiteMigration object at 0x7f64de8e38d0>,)
      kwargs = {}
      method = <function SiteMigration.run_schema_updates at 0x7f64de1b05e0>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 44, in wrapper
    ret = method(*args, **kwargs)
      args = (<frappe.migrate.SiteMigration object at 0x7f64de8e38d0>,)
      kwargs = {}
      method = <function SiteMigration.run_schema_updates at 0x7f64de1b05e0>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 121, in run_schema_updates
    frappe.modules.patch_handler.run_all(
      self = <frappe.migrate.SiteMigration object at 0x7f64de8e38d0>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 76, in run_all
    run_patch(patch)
      skip_failing = False
      patch_type = <PatchType.post_model_sync: 'post_model_sync'>
      executed = {'erpnext.patches.v13_0.create_custom_field_for_finance_book', 'execute:frappe.delete_doc("DocType", "Backup Manager")', 'insights.patches.rename_target_column_field', 'erpnext.patches.v15_0.rename_daily_depreciation_to_depreciation_amount_based_on_num_days_in_month', 'erpnext.patches.v15_0.drop_index_posting_datetime_from_sle', 'erpnext.patches.v12_0.add_permission_in_lower_deduction', 'frappe.patches.v14_0.update_is_system_generated_flag', 'erpnext.patches.v13_0.update_dates_in_tax_withholding_category', 'erpnext.patches.v13_0.fetch_thumbnail_in_website_items', 'erpnext.patches.v12_0.set_permission_einvoicing', 'erpnext.patches.v14_0.update_total_asset_cost_field', 'execute:frappe.reload_doc("HR", "doctype", "HR Settings") #2020-01-16 #2020-07-24', 'execute:frappe.delete_doc("Report", "Tax Detail", force=True)', 'erpnext.patches.v12_0.update_is_cancelled_field', 'builder.builder.doctype.builder_page.patches.enable_auto_convert_to_webp_by_default', "execute:frappe.delete_doc_if_exists...
      run_patch = <function run_all.<locals>.run_patch at 0x7f64de000180>
      patches = ["execute:frappe.get_doc('Role', 'Guest').save() # remove desk access", 'frappe.core.doctype.role.patches.v13_set_default_desk_properties', 'frappe.patches.v14_0.update_workspace2 # 06.06.2023', 'frappe.patches.v14_0.drop_data_import_legacy', 'frappe.patches.v14_0.copy_mail_data #08.03.21', 'frappe.patches.v14_0.update_github_endpoints #08-11-2021', 'frappe.patches.v14_0.remove_db_aggregation', 'frappe.patches.v14_0.update_color_names_in_kanban_board_column', 'frappe.patches.v14_0.update_is_system_generated_flag', 'frappe.patches.v14_0.update_auto_account_deletion_duration', 'frappe.patches.v14_0.update_integration_request', 'frappe.patches.v14_0.set_document_expiry_default', 'frappe.patches.v14_0.delete_data_migration_tool', 'frappe.patches.v14_0.set_suspend_email_queue_default', 'frappe.patches.v14_0.different_encryption_key', 'frappe.patches.v14_0.update_multistep_webforms', "execute:frappe.delete_doc('Page', 'background_jobs', ignore_missing=True, force=True)", 'frappe.patches.v14_...
      patch = 'erpnext.patches.v14_0.update_reports_with_range'
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 62, in run_patch
    if not run_single(patchmodule=patch):
      patch = 'erpnext.patches.v14_0.update_reports_with_range'
      skip_failing = False
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 152, in run_single
    return execute_patch(patchmodule, method, methodargs)
      patchmodule = 'erpnext.patches.v14_0.update_reports_with_range'
      method = None
      methodargs = None
      force = False
      conf = <LocalProxy unbound>
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 188, in execute_patch
    _patch()
      patchmodule = 'erpnext.patches.v14_0.update_reports_with_range'
      method = None
      methodargs = None
      has_patch_file = True
      patch = 'erpnext.patches.v14_0.update_reports_with_range.execute'
      docstring = ''
      _patch = <function execute at 0x7f64dd6a3c40>
      start_time = 21338048.127994344
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v14_0/update_reports_with_range.py", line 16, in execute
    update_reference_reports(report)
      report = 'Accounts Receivable'
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v14_0/update_reports_with_range.py", line 25, in update_reference_reports
    update_report_json(report)
      reference_report = 'Accounts Receivable'
      reports = [{'json': '{"columns":[{"label":"Posting Date","fieldname":"posting_date","fieldtype":"Date","options":null,"width":90,"id":"posting_date","name":"Posting Date","editable":false},{"label":"Customer","fieldname":"party","fieldtype":"Link","options":"Customer","width":180,"id":"party","name":"Customer","editable":false,"compareValue":null},{"fieldname":"customer_group_customer","field":"customer_group","fieldtype":"Link","label":"Customer Group","insert_after_index":1,"link_field":"party","doctype":"Customer","options":"Customer Group","width":100,"id":"customer_group_customer","name":"Customer Group","editable":false,"compareValue":null},{"label":"Receivable Account","fieldname":"party_account","fieldtype":"Link","options":"Account","width":180,"id":"party_account","name":"Receivable Account","editable":false,"compareValue":null},{"label":"Customer Contact","fieldname":"customer_primary_contact","fieldtype":"Link","options":"Contact","width":120,"id":"customer_primary_contact","name":"C...
      report = {'json': '{"columns":[{"label":"Posting Date","fieldname":"posting_date","fieldtype":"Date","options":null,"width":90,"id":"posting_date","name":"Posting Date","editable":false},{"label":"Customer","fieldname":"party","fieldtype":"Link","options":"Customer","width":180,"id":"party","name":"Customer","editable":false,"compareValue":null},{"fieldname":"customer_group_customer","field":"customer_group","fieldtype":"Link","label":"Customer Group","insert_after_index":1,"link_field":"party","doctype":"Customer","options":"Customer Group","width":100,"id":"customer_group_customer","name":"Customer Group","editable":false,"compareValue":null},{"label":"Receivable Account","fieldname":"party_account","fieldtype":"Link","options":"Account","width":180,"id":"party_account","name":"Receivable Account","editable":false,"compareValue":null},{"label":"Customer Contact","fieldname":"customer_primary_contact","fieldtype":"Link","options":"Contact","width":120,"id":"customer_primary_contact","name":"Cu...
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v14_0/update_reports_with_range.py", line 33, in update_report_json
    keys_to_pop = [key for key in report_filter if key.startswith("range")]
      report = {'json': '{"columns":[{"label":"Posting Date","fieldname":"posting_date","fieldtype":"Date","options":null,"width":90,"id":"posting_date","name":"Posting Date","editable":false},{"label":"Customer","fieldname":"party","fieldtype":"Link","options":"Customer","width":180,"id":"party","name":"Customer","editable":false,"compareValue":null},{"fieldname":"customer_group_customer","field":"customer_group","fieldtype":"Link","label":"Customer Group","insert_after_index":1,"link_field":"party","doctype":"Customer","options":"Customer Group","width":100,"id":"customer_group_customer","name":"Customer Group","editable":false,"compareValue":null},{"label":"Receivable Account","fieldname":"party_account","fieldtype":"Link","options":"Account","width":180,"id":"party_account","name":"Receivable Account","editable":false,"compareValue":null},{"label":"Customer Contact","fieldname":"customer_primary_contact","fieldtype":"Link","options":"Contact","width":120,"id":"customer_primary_contact","name":"Cu...
      report_json = {'columns': [{'label': 'Posting Date', 'fieldname': 'posting_date', 'fieldtype': 'Date', 'options': None, 'width': 90, 'id': 'posting_date', 'name': 'Posting Date', 'editable': False}, {'label': 'Customer', 'fieldname': 'party', 'fieldtype': 'Link', 'options': 'Customer', 'width': 180, 'id': 'party', 'name': 'Customer', 'editable': False, 'compareValue': None}, {'fieldname': 'customer_group_customer', 'field': 'customer_group', 'fieldtype': 'Link', 'label': 'Customer Group', 'insert_after_index': 1, 'link_field': 'party', 'doctype': 'Customer', 'options': 'Customer Group', 'width': 100, 'id': 'customer_group_customer', 'name': 'Customer Group', 'editable': False, 'compareValue': None}, {'label': 'Receivable Account', 'fieldname': 'party_account', 'fieldtype': 'Link', 'options': 'Account', 'width': 180, 'id': 'party_account', 'name': 'Receivable Account', 'editable': False, 'compareValue': None}, {'label': 'Customer Contact', 'fieldname': 'customer_primary_contact', 'fieldtype': 'Link',...
      report_filter = None
builtins.TypeError: 'NoneType' object is not iterable
```<hr>This is an automatic backport of pull request #43212 done by [Mergify](https://mergify.com).

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Sep 16, 2024
@ruthra-kumar ruthra-kumar merged commit bee27f3 into version-15-hotfix Sep 17, 2024
12 checks passed
@ruthra-kumar ruthra-kumar deleted the mergify/bp/version-15-hotfix/pr-43212 branch September 17, 2024 04:54
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants