Skip to content

Commit 3663a1d

Browse files
committed
fix test failure
1 parent 0ac965c commit 3663a1d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

supertokens_python/recipe/session/utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,9 @@ async def update_claims_in_payload_if_needed(
521521
log_debug_message(
522522
"update_claims_in_payload_if_needed checking %s", validator.id
523523
)
524-
if (
525-
hasattr(validator, "claim")
526-
and (validator.claim is not None)
527-
and (
528-
await resolve(
529-
validator.should_refetch(new_access_token_payload, user_context)
530-
)
524+
if (validator.claim is not None) and (
525+
await resolve(
526+
validator.should_refetch(new_access_token_payload, user_context)
531527
)
532528
):
533529
log_debug_message(

tests/sessions/claims/test_assert_claims.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Any, Dict, TypeVar, Union
23
from unittest.mock import patch
34

@@ -49,16 +50,19 @@ async def test_should_call_validate_with_the_same_payload_object():
4950
class DummyClaimValidator(SessionClaimValidator):
5051
def __init__(self, claim: SessionClaim[Any]):
5152
super().__init__("claim_validator_id", claim)
52-
self.validate_call_count = 0
53+
self.validate_calls: Dict[str, int] = {}
5354

5455
async def validate(
5556
self, payload: JSONObject, user_context: Union[Dict[str, Any], None] = None
5657
):
57-
self.validate_call_count += 1
58+
payload_json = json.dumps(payload)
59+
self.validate_calls[payload_json] = (
60+
self.validate_calls.get(payload_json, 0) + 1
61+
)
5862
return ClaimValidationResult(is_valid=True)
5963

6064
def should_refetch(self, payload: JSONObject, user_context: Dict[str, Any]):
61-
return True
65+
return False
6266

6367
dummy_claim = PrimitiveClaim("st-claim", lambda _, __: "Hello world")
6468

@@ -72,6 +76,6 @@ def should_refetch(self, payload: JSONObject, user_context: Dict[str, Any]):
7276
wraps=session.update_access_token_payload,
7377
) as mock:
7478
await session.assert_claims([dummy_claim.validators.dummy_claim_validator]) # type: ignore
75-
mock.assert_not_called()
7679

77-
assert dummy_claim_validator.validate_call_count == 1
80+
assert dummy_claim_validator.validate_calls == {json.dumps(payload): 1}
81+
mock.assert_not_called()

0 commit comments

Comments
 (0)