fix: initialize user_can_view before conditional hook check#2777
Open
veeceey wants to merge 1 commit intoChainlit:mainfrom
Open
fix: initialize user_can_view before conditional hook check#2777veeceey wants to merge 1 commit intoChainlit:mainfrom
veeceey wants to merge 1 commit intoChainlit:mainfrom
Conversation
Author
|
Reviewer feedback addressed ✓ Mergeable: YES | All checks passing. Size: XS. Ready for @Chainlit/core team review and merge. |
Author
Manual Test ResultsTest 1: Accessing shared thread without
|
Author
|
Hi team, friendly ping on this PR. It's been open for a couple of days now and all checks are passing. Would anyone from the maintainer team have a chance to take a look when convenient? Happy to address any feedback. Thanks! |
b18309d to
1f7a0ce
Compare
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.
Summary
UnboundLocalError: cannot access local variable 'user_can_view'when@cl.on_shared_thread_viewhook is not defineduser_can_view = Falsebefore the conditional block that checks for the hook, ensuring the variable always has a value when evaluated on the subsequent guard checkFixes #2766
Root Cause
In
get_shared_thread(), the variableuser_can_viewis only assigned inside theif getattr(config.code, "on_shared_thread_view", None):block. When the hook is not defined, this block is skipped entirely, butuser_can_viewis still referenced on the next line:This raises an
UnboundLocalError.Fix
Add
user_can_view = Falseas a safe default before the conditional hook check. This is consistent with the behavior inside theexceptblock which also defaults toFalse.Test plan
@cl.on_shared_thread_view/project/share/{thread_id})UnboundLocalErroris raisedis_shared=Truemetadata are still accessibleSummary by cubic
Initialize user_can_view to False before checking for on_shared_thread_view in get_shared_thread. This avoids UnboundLocalError when the hook is missing and keeps shared vs. non-shared access checks working as expected.
Written for commit 1f7a0ce. Summary will update on new commits.