Skip to content

Add Litestar framework #483

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add Litestar framework #483

wants to merge 4 commits into from

Conversation

bpereto
Copy link

@bpereto bpereto commented Apr 8, 2024

Summary of change

Adds the litestar framework as option for backend python integration.

Related issues

Test Plan

project should update the test environment to at least python3.8.

Documentation changes

Checklist for important updates

  • Changelog has been updated
  • coreDriverInterfaceSupported.json file has been updated (if needed)
    • Along with the associated array in supertokens_python/constants.py
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In setup.py
    • In supertokens_python/constants.py
  • Had installed and ran the pre-commit hook
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • If have added a new web framework, update the supertokens_python/utils.py file to include that in the FRAMEWORKS variable
  • If added a new recipe that has a User type with extra info, then be sure to change the User type in supertokens_python/types.py
  • Make sure that syncio / asyncio functions are consistent.
  • If access token structure has changed
    • Modified test in tests/sessions/test_access_token_version.py to account for any new claims that are optional or omitted by the core

Remaining TODOs for this PR

  • Item1
  • Item2

@bpereto bpereto mentioned this pull request Apr 8, 2024
@rishabhpoddar
Copy link
Contributor

Thanks @bpereto. Ill have a detailed look at this soon. In the meantime though, a few things are missing:

  • An example app in the examples folder.
  • Missing frontend integration server (in tests/frontendIntegration/ folder)

Comment on lines +1 to +13
from __future__ import annotations
from typing import Any, Callable, Coroutine, TYPE_CHECKING

from litestar import Request

from supertokens_python.framework.litestar.litestar_request import LitestarRequest
from .litestar_middleware import get_middleware

if TYPE_CHECKING:
from ...recipe.session import SessionRecipe, SessionContainer
from ...recipe.session.interfaces import SessionClaimValidator
from ...types import MaybeAwaitable

Copy link

Choose a reason for hiding this comment

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

The SessionRecipe class is imported inside the TYPE_CHECKING block, but it's actually used at runtime in the verify_session function. This will cause a runtime error when the function is called. Please add from ...recipe.session import SessionRecipe outside the TYPE_CHECKING block to make it available during execution.

Suggested change
from __future__ import annotations
from typing import Any, Callable, Coroutine, TYPE_CHECKING
from litestar import Request
from supertokens_python.framework.litestar.litestar_request import LitestarRequest
from .litestar_middleware import get_middleware
if TYPE_CHECKING:
from ...recipe.session import SessionRecipe, SessionContainer
from ...recipe.session.interfaces import SessionClaimValidator
from ...types import MaybeAwaitable
from __future__ import annotations
from typing import Any, Callable, Coroutine, TYPE_CHECKING
from litestar import Request
from supertokens_python.framework.litestar.litestar_request import LitestarRequest
from .litestar_middleware import get_middleware
from ...recipe.session import SessionRecipe
if TYPE_CHECKING:
from ...recipe.session import SessionContainer
from ...recipe.session.interfaces import SessionClaimValidator
from ...types import MaybeAwaitable

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

refresh_session,
)
from supertokens_python.recipe.session.exceptions import UnauthorisedError
from supertokens_python.recipe.session.framework.litestar import verify_session
Copy link

Choose a reason for hiding this comment

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

The import from supertokens_python.recipe.session.framework.litestar import verify_session references a module path that doesn't appear to be included in this PR. The directory structure recipe/session/framework/litestar/ and its corresponding __init__.py file need to be created with the verify_session function properly exported. Please add these missing files to ensure the import will work correctly when the code is deployed.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

"/handle-session-optional",
dependencies={"session": Provide(verify_session(session_required=False))},
)
def handle_get_optional(session: SessionContainer) -> dict[str, Any]:
Copy link

Choose a reason for hiding this comment

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

The type annotation for session parameter should be SessionContainer | None since verify_session with session_required=False can return None. This would make the type annotation consistent with the actual possible return values and prevent potential type checking errors.

Suggested change
def handle_get_optional(session: SessionContainer) -> dict[str, Any]:
def handle_get_optional(session: SessionContainer | None) -> dict[str, Any]:

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

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.

2 participants