Skip to content

Commit dc9c3be

Browse files
committed
changes suggested in PR feedback
1 parent e77328e commit dc9c3be

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

supertokens_python/recipe/session/asyncio/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from supertokens_python.recipe.session.recipe import SessionRecipe
3131
from supertokens_python.types import MaybeAwaitable
32-
from supertokens_python.utils import FRAMEWORKS, resolve
32+
from supertokens_python.utils import FRAMEWORKS, resolve, deprecated_warn
3333
from ..utils import get_required_claim_validators
3434
from ...jwt.interfaces import (
3535
CreateJwtOkResult,
@@ -54,7 +54,9 @@ async def create_new_session(
5454
if access_token_payload is None:
5555
access_token_payload = {}
5656

57-
claims_added_by_other_recipes = SessionRecipe.get_claims_added_by_other_recipes()
57+
claims_added_by_other_recipes = (
58+
SessionRecipe.get_instance().get_claims_added_by_other_recipes()
59+
)
5860
final_access_token_payload = access_token_payload
5961

6062
for claim in claims_added_by_other_recipes:
@@ -101,7 +103,7 @@ async def validate_claims_for_session_handle(
101103
return SessionDoesNotExistError()
102104

103105
claim_validators_added_by_other_recipes = (
104-
SessionRecipe.get_claim_validators_added_by_other_recipes()
106+
SessionRecipe.get_instance().get_claim_validators_added_by_other_recipes()
105107
)
106108
global_claim_validators = await resolve(
107109
recipe_impl.get_global_claim_validators(
@@ -146,7 +148,7 @@ async def validate_claims_in_jwt_payload(
146148
recipe_impl = SessionRecipe.get_instance().recipe_implementation
147149

148150
claim_validators_added_by_other_recipes = (
149-
SessionRecipe.get_claim_validators_added_by_other_recipes()
151+
SessionRecipe.get_instance().get_claim_validators_added_by_other_recipes()
150152
)
151153
global_claim_validators = await resolve(
152154
recipe_impl.get_global_claim_validators(
@@ -338,6 +340,11 @@ async def update_access_token_payload(
338340
) -> bool:
339341
if user_context is None:
340342
user_context = {}
343+
344+
deprecated_warn(
345+
"update_access_token_payload is deprecated. Use merge_into_access_token_payload instead"
346+
)
347+
341348
return await SessionRecipe.get_instance().recipe_implementation.update_access_token_payload(
342349
session_handle, new_access_token_payload, user_context
343350
)

supertokens_python/recipe/session/claim_base_classes/primitive_claim.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
class HasValueSCV(SessionClaimValidator):
3232
def __init__(self, id_: str, claim: SessionClaim[_T], val: _T):
33-
super().__init__(id_, claim)
33+
super().__init__(id_)
34+
self.claim: SessionClaim[_T] = claim # Required to fix the type for pyright
3435
self.val = val
3536

3637
def should_refetch(
@@ -63,7 +64,8 @@ async def validate(
6364

6465
class HasFreshValueSCV(SessionClaimValidator):
6566
def __init__(self, id_: str, claim: SessionClaim[_T], val: _T, max_age_in_sec: int):
66-
super().__init__(id_, claim)
67+
super().__init__(id_)
68+
self.claim: SessionClaim[_T] = claim
6769
self.val = val
6870
self.max_age_in_sec = max_age_in_sec
6971

supertokens_python/recipe/session/interfaces.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ async def get_claim_value(
450450
@abstractmethod
451451
async def remove_claim(
452452
self,
453-
claim: SessionClaim[_T], # pyright: ignore[reportInvalidTypeVarUse]
453+
claim: SessionClaim[Any],
454454
user_context: Union[Dict[str, Any], None] = None,
455455
) -> None:
456456
pass
@@ -602,7 +602,9 @@ class SessionClaimValidator(ABC):
602602
def __init__(
603603
self,
604604
id_: str,
605-
claim: SessionClaim[_T], # pyright: ignore[reportInvalidTypeVarUse]
605+
claim: Optional[
606+
SessionClaim[_T] # pyright: ignore[reportInvalidTypeVarUse]
607+
] = None,
606608
) -> None:
607609
self.id = id_
608610
self.claim = claim
@@ -613,9 +615,7 @@ async def validate(
613615
) -> ClaimValidationResult:
614616
pass
615617

616-
@abstractmethod
617618
def should_refetch(
618619
self, payload: JSONObject, user_context: Dict[str, Any]
619620
) -> MaybeAwaitable[bool]:
620-
# TODO: Confirm that MaybeAwaitable actually makes the function async
621-
pass
621+
raise NotImplementedError()

supertokens_python/recipe/session/recipe.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,27 +303,27 @@ def reset():
303303
raise_general_exception("calling testing function in non testing env")
304304
SessionRecipe.__instance = None
305305

306-
@staticmethod
307-
def add_claim_from_other_recipe(claim: SessionClaim[Any]):
306+
def add_claim_from_other_recipe(self, claim: SessionClaim[Any]):
308307
# We are throwing here (and not in addClaimValidatorFromOtherRecipe) because if multiple
309308
# claims are added with the same key they will overwrite each other. Validators will all run
310309
# and work as expected even if they are added multiple times.
311-
if claim.key in [c.key for c in SessionRecipe.claims_added_by_other_recipes]:
310+
if claim.key in [c.key for c in self.claims_added_by_other_recipes]:
312311
raise Exception("Claim added by multiple recipes")
313312

314-
SessionRecipe.claims_added_by_other_recipes.append(claim)
313+
self.claims_added_by_other_recipes.append(claim)
315314

316-
@staticmethod
317-
def get_claims_added_by_other_recipes() -> List[SessionClaim[Any]]:
318-
return SessionRecipe.claims_added_by_other_recipes
315+
def get_claims_added_by_other_recipes(self) -> List[SessionClaim[Any]]:
316+
return self.claims_added_by_other_recipes
319317

320-
@staticmethod
321-
def add_claim_validator_from_other_recipe(claim_validator: SessionClaimValidator):
322-
SessionRecipe.claim_validators_added_by_other_recipes.append(claim_validator)
318+
def add_claim_validator_from_other_recipe(
319+
self, claim_validator: SessionClaimValidator
320+
):
321+
self.claim_validators_added_by_other_recipes.append(claim_validator)
323322

324-
@staticmethod
325-
def get_claim_validators_added_by_other_recipes() -> List[SessionClaimValidator]:
326-
return SessionRecipe.claim_validators_added_by_other_recipes
323+
def get_claim_validators_added_by_other_recipes(
324+
self,
325+
) -> List[SessionClaimValidator]:
326+
return self.claim_validators_added_by_other_recipes
327327

328328
async def verify_session(
329329
self,

supertokens_python/recipe/session/recipe_implementation.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
get_timestamp_ms,
2626
normalise_http_method,
2727
resolve,
28-
deprecated_warn,
2928
)
3029
from . import session_functions
3130
from .cookie_and_header import (
@@ -402,9 +401,6 @@ async def update_access_token_payload(
402401
new_access_token_payload: Dict[str, Any],
403402
user_context: Dict[str, Any],
404403
) -> bool:
405-
deprecated_warn(
406-
"update_access_token_payload is deprecated. Use merge_into_access_token_payload instead"
407-
)
408404

409405
return await session_functions.update_access_token_payload(
410406
self, session_handle, new_access_token_payload

supertokens_python/recipe/session/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ async def get_required_claim_validators(
491491
from .recipe import SessionRecipe
492492

493493
claim_validators_added_by_other_recipes = (
494-
SessionRecipe.get_claim_validators_added_by_other_recipes()
494+
SessionRecipe.get_instance().get_claim_validators_added_by_other_recipes()
495495
)
496496
global_claim_validators = await resolve(
497497
SessionRecipe.get_instance().recipe_implementation.get_global_claim_validators(

supertokens_python/recipe/session/with_jwt/recipe_implementation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from jwt import decode
1919

20-
from supertokens_python.utils import get_timestamp_ms, deprecated_warn
20+
from supertokens_python.utils import get_timestamp_ms
2121

2222
from .constants import ACCESS_TOKEN_PAYLOAD_JWT_PROPERTY_NAME_KEY
2323
from .session_class import get_session_with_jwt
@@ -188,9 +188,6 @@ async def update_access_token_payload(
188188
new_access_token_payload: Dict[str, Any],
189189
user_context: Dict[str, Any],
190190
) -> bool:
191-
deprecated_warn(
192-
"update_access_token_payload is deprecated. Use merge_into_access_token_payload instead"
193-
)
194191

195192
session_information = await original_implementation.get_session_information(
196193
session_handle, user_context

0 commit comments

Comments
 (0)