This repository was archived by the owner on Sep 8, 2025. It is now read-only.
feat: rewrite enumerated literals as Enums#633
Open
juancarlospaco wants to merge 11 commits intosupabase:mainfrom
Open
feat: rewrite enumerated literals as Enums#633juancarlospaco wants to merge 11 commits intosupabase:mainfrom
juancarlospaco wants to merge 11 commits intosupabase:mainfrom
Conversation
|
@juancarlospaco what's the benefits of using the |
Contributor
Author
|
It can check if the value is in the range of the enum, for extra safety. Enum can be a more correct representation of "enumerated string values". |
grdsdev
reviewed
Nov 27, 2024
J0
reviewed
Dec 11, 2024
J0
approved these changes
Dec 12, 2024
Co-authored-by: Joel Lee <lee.yi.jie.joel@gmail.com>
silentworks
suggested changes
Dec 17, 2024
Contributor
silentworks
left a comment
There was a problem hiding this comment.
I'm going to leave this PR parked as when I test it locally in my existing app which makes use of the literals for type hint it breaks the type checking. This is a big breaking change and should be done at the next major version change.
Contributor
|
Example of breaking changes: # this is now broken because "provider" is expecting a enum class instance
resp = await supabase.auth.link_identity(
{
"provider": "google",
"options": {"redirect_to": f"{request.base_url}auth/callback"},
}
)now becomes resp = await supabase.auth.link_identity(
{
"provider": Provider("google"),
"options": {"redirect_to": f"{request.base_url}auth/callback"},
}
)And a more full FastAPI function that uses hinting inside of the params async def confirm(
request: Request,
token_hash: str,
type: EmailOtpType = "email",
supabase: AClient = Depends(create_supabase),
):
try:
if token_hash and type:
if type == "recovery":
request.session["password_update_required"] = True
await supabase.auth.verify_otp(
params={"token_hash": token_hash, "type": type}
)
return {"message": "User signed in successfully."}
...now becomes async def confirm(
request: Request,
token_hash: str,
type: EmailOtpType | None = None,
supabase: AClient = Depends(create_supabase),
):
try:
if not isinstance(type, EmailOtpType):
type = EmailOtpType("email" if type is None else type)
if token_hash and type:
if type.value == "recovery":
request.session["password_update_required"] = True
await supabase.auth.verify_otp(
params={"token_hash": token_hash, "type": type}
)
return {"message": "User signed in successfully."}
... |
Contributor
Author
|
I agree with the parking, it can sleep for a while. 👍 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What kind of change does this PR introduce?