Skip to content

fix(env): resolve get_ol_env() name collision causing 500 - #13268

Merged
RayBB merged 2 commits into
masterfrom
fix/env-collision-get-ol-env
Aug 5, 2026
Merged

fix(env): resolve get_ol_env() name collision causing 500#13268
RayBB merged 2 commits into
masterfrom
fix/env-collision-get-ol-env

Conversation

@RayBB

@RayBB RayBB commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

Rendering / failed with TypeError: can only concatenate str (not "OLEnv") to str at lib/nav_head.html:57:

' logo-txt--env-' + ol_env

Root cause

Two PRs added a function named get_ol_env() with different return types:

  • string helper get_ol_env() -> str in plugins/upstream/utils.py, used by templates for the env badge/favicon
  • get_ol_env() -> OLEnv (config flags .LOCAL_DEV, .OL_EXPOSE_SOLR_INTERNALS_PARAMS) in core/env.py, registered into template globals by plugins/openlibrary/code.py

The Template.globals.update won, so templates resolved the name to the OLEnv object β€” but the templates expected a string β€” breaking the concatenation.

Fix

  • core/env.py: add get_ol_env_name() -> str hosting the host-based badge logic; plugins/upstream/utils.py: drop the string duplicate
  • plugins/openlibrary/code.py: register get_ol_env_name alongside get_ol_env
  • templates/lib/nav_head.html + templates/site/head.html: call get_ol_env_name() for the badge/favicon; .LOCAL_DEV usages on the OLEnv object remain unchanged

Validation

  • / returns 200, renders the logo-txt--env-development badge and dev favicons
  • get_ol_env() (the object) is untouched, so all shared callers are unaffected
  • ruff check / ruff format pass

Two PRs introduced a function named get_ol_env() with different return types:
the host-based string helper in upstream/utils.py and the OLEnv object in
core/env.py registered into template globals. The globals.update won, so
templates resolved the name to the OLEnv object while expecting a string,
breaking concatenation in nav_head.html.

Give each a distinct name: add get_ol_env_name() in core/env.py hosting the
badge/favicon logic, remove the string duplicate, register it alongside
get_ol_env(), and point the badge/favicon templates at the new helper. The
OLEnv object and all .LOCAL_DEV usages are unchanged.

@lokesh lokesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RayBB
RayBB merged commit 6b06f1b into master Aug 5, 2026
8 checks passed
@RayBB
RayBB deleted the fix/env-collision-get-ol-env branch August 5, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants