Skip to content

Default request context lang to 'en' to silence unhelpful error logs#12336

Merged
RayBB merged 1 commit intointernetarchive:masterfrom
cdrini:12070/fix/request-ctx-lang
Apr 9, 2026
Merged

Default request context lang to 'en' to silence unhelpful error logs#12336
RayBB merged 1 commit intointernetarchive:masterfrom
cdrini:12070/fix/request-ctx-lang

Conversation

@cdrini
Copy link
Copy Markdown
Collaborator

@cdrini cdrini commented Apr 9, 2026

Closes #12070 . This was also causing the error logs to explode in size on our prod cluster, so needed some intervention.

Technical

Testing

Tested on testing, and the logs are quiet again!

Screenshot

Stakeholders

Copilot AI review requested due to automatic review settings April 9, 2026 17:06
@github-actions github-actions Bot added the Priority: 2 Important, as time permits. [managed] label Apr 9, 2026
@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents request-context initialization from failing when a language isn’t present on web.ctx / request.state, by defaulting the request-context lang to "en". This addresses the AttributeError: 'ThreadedDict' object has no attribute 'lang' reported in #12070, especially for scripts/crons/background-thread execution paths that don’t fully populate web.ctx.

Changes:

  • Default RequestContextVars.lang to "en" when web.ctx.lang is missing/falsey in the legacy web.py context setup.
  • Default RequestContextVars.lang to "en" when request.state.lang is falsey in the FastAPI context setup.

Copy link
Copy Markdown
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

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

We discussed this and walked through it on the call. This is what we need to stop some error messages.

@RayBB RayBB merged commit 4927938 into internetarchive:master Apr 9, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Apr 9, 2026
@cdrini cdrini changed the title Default request context lang to 'en' to silent unhelpful error logs Default request context lang to 'en' to silence unhelpful error logs Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: 2 Important, as time permits. [managed]

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

FastAPI ContextVar (e.g. lang=web.ctx.lang) breaks w/ scripts, crons, bg threads

3 participants