-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use AsyncSession for user management #4491
Conversation
45ad310
to
5e4b3a9
Compare
query: SelectOfScalar = select(ApiKey).options(selectinload(ApiKey.user)).where(ApiKey.api_key == api_key) | ||
api_key_object: ApiKey | None = (await session.exec(query)).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why get the user here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because here:
https://github.com/langflow-ai/langflow/blob/main/src/backend/base/langflow/services/auth/utils.py#L71-L72
the ApiKey.user is referenced but lazy-loading doesn't work with AsyncSession.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified check_key
to return the user instead of the ApiKey.
This way the result is easier to check.
PTAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -431,7 +431,7 @@ def get_variable(name: str, field: str): | |||
|
|||
return get_variable | |||
|
|||
def list_key_names(self): | |||
async def list_key_names(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this one async. Is it OK ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes but for backwards compatibility we have to keep it a sync version of it with this name and create a new one. This one then can just call run_until_complete or something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Reverted to sync version and added list_variables_sync
in VariableService
query: SelectOfScalar = select(ApiKey).options(selectinload(ApiKey.user)).where(ApiKey.api_key == api_key) | ||
api_key_object: ApiKey | None = (await session.exec(query)).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because here:
https://github.com/langflow-ai/langflow/blob/main/src/backend/base/langflow/services/auth/utils.py#L71-L72
the ApiKey.user is referenced but lazy-loading doesn't work with AsyncSession.
fdb4bc1
to
674559f
Compare
CodSpeed Performance ReportMerging #4491 will degrade performances by 78.78%Comparing Summary
Benchmarks breakdown
|
bd750a5
to
0a3000d
Compare
72b72bc
to
426764f
Compare
426764f
to
828276e
Compare
1d5e7c8
to
f562ecf
Compare
* Use AsyncSession for user management * Simplify check_key * Don't trigger blockbuster on settings service initialize * Fix mypy * Fix api key update_total_uses * Fix auto-login * Revert making CustomComponent.list_key_names async
Use AsyncSession for user management