Skip to content
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 'itsdangerous' import error when not using Authentication Backend #597

Merged
merged 2 commits into from
Sep 5, 2023
Merged

Fix 'itsdangerous' import error when not using Authentication Backend #597

merged 2 commits into from
Sep 5, 2023

Conversation

GriceTurrble
Copy link
Contributor

Issue

When importing sqladmin.Admin:

from sqladmin import Admin

...the application imports from .authentication:

from sqladmin.authentication import AuthenticationBackend, login_required

Which in turn calls starlette.middleware.sessions:

from starlette.middleware.sessions import SessionMiddleware

And in starlette package, middleware.session tries to import itsdangerous: https://github.com/encode/starlette/blob/cb6d284877cd359a21a0f31ebf8103a7b285a848/starlette/middleware/sessions.py#L5

However, this package is not installed automatically: it's part of the "full" deps: https://github.com/encode/starlette/blob/cb6d284877cd359a21a0f31ebf8103a7b285a848/pyproject.toml#L37

Therefore, it's easily possible to install sqladmin and not this crucial sub-dependency, creating an error when trying to run the site:
image

Solution

Either:

  1. Mark itsdangerous as a named dependency here (which seems odd to name a sub-dependency just to alleviate this issue); or
  2. Install starlette[full] as a main dependency, ensuring all dependencies are covered up front.

This PR is a simple change implementing the latter.

Copy link
Owner

@aminalaee aminalaee left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, I had missed this for a long time.

pyproject.toml Outdated Show resolved Hide resolved
@aminalaee aminalaee changed the title fix: use starlette[full] to ensure correct deps Fix 'itsdangerous' import error when not using Authentication Backend Sep 5, 2023
Copy link
Owner

@aminalaee aminalaee left a comment

Choose a reason for hiding this comment

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

Thanks for the fix 👍

@aminalaee aminalaee merged commit b4d2f2d into aminalaee:main Sep 5, 2023
6 checks passed
@GriceTurrble GriceTurrble deleted the fix/starlette-full-deps branch September 13, 2023 17:26
@aminalaee aminalaee mentioned this pull request Sep 19, 2023
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.

None yet

2 participants