fix(env): resolve get_ol_env() name collision causing 500 - #13268
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Rendering
/failed withTypeError: can only concatenate str (not "OLEnv") to stratlib/nav_head.html:57:Root cause
Two PRs added a function named
get_ol_env()with different return types:get_ol_env() -> strinplugins/upstream/utils.py, used by templates for the env badge/faviconget_ol_env() -> OLEnv(config flags.LOCAL_DEV,.OL_EXPOSE_SOLR_INTERNALS_PARAMS) incore/env.py, registered into template globals byplugins/openlibrary/code.pyThe
Template.globals.updatewon, so templates resolved the name to theOLEnvobject β but the templates expected a string β breaking the concatenation.Fix
core/env.py: addget_ol_env_name() -> strhosting the host-based badge logic;plugins/upstream/utils.py: drop the string duplicateplugins/openlibrary/code.py: registerget_ol_env_namealongsideget_ol_envtemplates/lib/nav_head.html+templates/site/head.html: callget_ol_env_name()for the badge/favicon;.LOCAL_DEVusages on theOLEnvobject remain unchangedValidation
/returns 200, renders thelogo-txt--env-developmentbadge and dev faviconsget_ol_env()(the object) is untouched, so all shared callers are unaffectedruff check/ruff formatpass