press icon indicating copy to clipboard operation
press copied to clipboard

fix(hooks): Prevent get_frappe_io_auth_url() from being called during bench version execution

Open asaura08 opened this issue 6 months ago • 2 comments

Fixes: https://github.com/frappe/press/issues/2656

This PR fixes a runtime error that occurs when executing bench version due to an unguarded call to get_frappe_io_auth_url() inside website_redirects in hooks.py.

When bench version is run, the site context is not initialized, which causes frappe.get_last_doc() (used within get_frappe_io_auth_url) to fail with a RuntimeError: object is not bound.

To address this, the function call is now conditionally executed only if the script is not being invoked with bench version, using sys.orig_argv as a check. If the check fails, a fallback path ("/") is used instead.

This ensures compatibility with CLI commands like bench version while preserving the intended login redirection logic during normal runtime.

asaura08 avatar Jun 05 '25 16:06 asaura08

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 44.81%. Comparing base (004d817) to head (6582428). :warning: Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2750   +/-   ##
========================================
  Coverage    44.81%   44.81%           
========================================
  Files          723      723           
  Lines        49504    49505    +1     
========================================
+ Hits         22185    22186    +1     
  Misses       27319    27319           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 05 '25 16:06 codecov[bot]

@balamurali27 Maybe try

if not hasattr(frappe.local, "db"):
    return None

adityahase avatar Sep 18 '25 10:09 adityahase