Skip to content

fix(gt-fastapi): loading behavior#19

Merged
ErnestM1234 merged 2 commits intomainfrom
e/gt-i18n/fix-declare-static
Mar 8, 2026
Merged

fix(gt-fastapi): loading behavior#19
ErnestM1234 merged 2 commits intomainfrom
e/gt-i18n/fix-declare-static

Conversation

@ErnestM1234
Copy link
Contributor

@ErnestM1234 ErnestM1234 commented Mar 8, 2026

Greptile Summary

This PR fixes a bug in gt-fastapi where eager loading of translations was skipped whenever locales was not explicitly passed to initialize_gt(), even if locales were correctly resolved from a config file.

Key changes:

  • Bug fix in _setup.py: The eager-loading guard changed from if eager_loading and locales: to if eager_loading and resolved_locales:. resolved_locales is the merged result of the function argument and the config-file fallback, so this correctly enables preloading when locales are defined only in gt.config.json.
  • Changeset added: A patch-level changeset (venerable-shaman-mielikki.md) is included to track the version bump for pypi/gt-fastapi.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted one-line bug fix with no side effects on existing behaviour.
  • The change is a single-line fix that corrects variable shadowing in a conditional check. The logic is straightforward: resolved_locales already accounts for the None case and the config-file fallback. No new dependencies, no structural changes, and the existing lifespan/middleware wiring is untouched.
  • No files require special attention.

Important Files Changed

Filename Overview
packages/gt-fastapi/src/gt_fastapi/_setup.py One-line bug fix: the eager-loading guard now correctly uses resolved_locales (which includes config-file fallback) instead of the raw locales parameter, which could be None even when locales are defined in the config file.
.sampo/changesets/venerable-shaman-mielikki.md Changeset file marking a patch-level version bump for pypi/gt-fastapi to accompany the bug fix.

Sequence Diagram

sequenceDiagram
    participant App as FastAPI App
    participant init as initialize_gt()
    participant cfg as load_gt_config()
    participant mgr as I18nManager
    participant cdn as CDN / Translation Store

    App->>init: initialize_gt(app, locales=None, eager_loading=True, ...)
    init->>cfg: load_gt_config()
    cfg-->>init: file_config (may include locales)
    init->>init: resolved_locales = locales or file_config.get("locales")
    init->>mgr: I18nManager(resolved_locales, ...)
    init->>App: wrap lifespan → _gt_lifespan

    Note over App,cdn: At startup (lifespan)
    App->>init: _gt_lifespan triggered
    alt eager_loading AND resolved_locales
        init->>mgr: load_all_translations()
        mgr->>cdn: fetch translations for each locale
        cdn-->>mgr: translation data
    else no locales or eager_loading=False
        Note over init,mgr: skip preloading
    end

    Note over App,mgr: Per-request middleware
    App->>init: HTTP request arrives
    init->>init: detect locale (Accept-Language or get_locale())
    init->>mgr: set_locale(locale)
    mgr-->>App: locale set for request scope
Loading

Last reviewed commit: cb0b561

Greptile also left 1 inline comment on this PR.

@ErnestM1234 ErnestM1234 changed the title E/gt i18n/fix declare static fix(gt-fastapi): loading behavior Mar 8, 2026
@ErnestM1234 ErnestM1234 merged commit 03765a5 into main Mar 8, 2026
9 of 10 checks passed
@ErnestM1234 ErnestM1234 deleted the e/gt-i18n/fix-declare-static branch March 8, 2026 05:23
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