fix(library-assistant): write the settings key when a profile is created - #3638
Open
dcschreiber wants to merge 6 commits into
Open
fix(library-assistant): write the settings key when a profile is created#3638dcschreiber wants to merge 6 commits into
dcschreiber wants to merge 6 commits into
Conversation
… profile creation Email registration is the only signup path that writes settings.library_assistant, so brand-new SSO accounts (and lazily-created profiles for existing Django users) come out keyless and read assistant-off. Write the key, exactly as process_register_form does, in both remaining profile-creation paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📊 Code Quality Score: 6/100
Was this score accurate? 👍 Yes · 👎 No Scored by GitVelocity · How are scores calculated? |
…aceLang Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The helper now imports the user_profile module instead of binding the class at import time, which breaks the cycle and lets user_profile import the helper normally. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ing docs These tests built the pre-migration 'no setting key' premise by deleting the profile doc and relying on lazy creation to rebuild it keyless. Profile creation now writes the key on every path, so the premise is built explicitly instead: create the doc, then unset the key. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n choke point UserProfile.__init__ sets the key whenever no stored doc exists, so every creation path (email registration, SSO, lazy creation) inherits it and none can miss it. The per-path write in process_register_form becomes redundant and is removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Centralizes the Library Assistant default for newly created profiles, covering email, SSO, and lazy creation paths.
Changes:
- Initializes new profiles with Library Assistant enabled.
- Removes the redundant registration-specific write.
- Updates helper imports and legacy-profile tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
sefaria/views.py |
Removes registration-specific initialization. |
sefaria/model/user_profile.py |
Initializes the setting for new profiles. |
sefaria/helper/library_assistant.py |
Avoids circular class imports. |
sefaria/helper/tests/library_assistant_test.py |
Updates the mocked class path. |
reader/conftest.py |
Adds a keyless legacy-profile helper. |
reader/tests/library_assistant_setting_test.py |
Tests creation and legacy behavior. |
reader/tests/enable_library_assistant_test.py |
Preserves the keyless cross-site scenario. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| self.settings[library_assistant.SETTING_KEY] = True | ||
| if self.exists() and not user_registration: | ||
| # If we encounter a user that has a Django user record but not a profile document | ||
| # create a profile for them. This allows two enviornments to share a user database, |
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.
(Claude writing on Daniel's behalf)
New SSO accounts never get
settings.library_assistant. Email registration wrote the key at signup, but the SSO adapter (#3511) and the lazy profile-creation branch inUserProfile.__init__did not. Those users read as assistant-off today, and Phase 3 (#3579) would make that permanent. This bug blocks Phase 3 of the Library Assistant opt-out rollout (sc-46274).What changes
The key is now written in one place instead of once per signup path:
UserProfile.__init__setssettings.library_assistant = Truewhen no stored profile doc exists. Every creation path passes through that point, so email registration, SSO, and lazy creation all inherit the write, and a future creation path cannot miss it. The per-path write inprocess_register_formbecame redundant and is removed.Why not a settings default: defaults don't stay read-only here.
UserProfilelays the stored doc over its defaults, andsave()writes the merged result back. A defaultTruewould make every existing keyless profile read as on, and their next save would persist that as if the user chose it. Writing the key only when no doc exists yet leaves existing docs untouched: absent stays absent.Also in the diff:
make_keyless_profileinreader/conftest.py).library_assistant.pyimports theuser_profilemodule instead of binding the class, souser_profilecan import it back without a cycle.Not in this PR: the backfill of keyless profiles created since the Aug 10 migration. That runs as an ops step before the Phase 3 deploy. The backfill rule: whitelist-row value wins, no row means on.
How we tested
We ran a real SSO signup end to end against the local databases, before and after the fix. The test drives
POST /api/auth/google/mobilein-process and mocks only Google'sverify_token(plus reCAPTCHA on the email control path). Everything else runs for real: allauth, the adapter, and the Mongo write.settings.library_assistant.is_enabledreturns False, the settings toggle renders Off, and reader pages emit no chatbot script tag.true, and all three checks flip to on. Both the SSO run and the register control were re-run after consolidating the write intoUserProfile.__init__; both get the key._id,id, andslug.library_assistant: true.pyteston the sso, helper, and Library Assistant reader test files: 107/107 green.cc @YishaiGlasner (SSO owner): no
sso/changes needed in the final shape — the adapter inherits the write from profile creation.🤖 Generated with Claude Code