Skip to content

Commit

Permalink
removed extra attribute from input schema
Browse files Browse the repository at this point in the history
  • Loading branch information
eadwinCode committed Nov 8, 2023
1 parent c052d5d commit 36ef232
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ninja_jwt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_token(cls, user: AbstractUser) -> Dict:

class TokenObtainInputSchemaBase(ModelSchema, TokenInputSchemaMixin):
class Config:
extra = "allow"
# extra = "allow"
model = get_user_model()
model_fields = ["password", user_name_field]

Expand Down Expand Up @@ -126,7 +126,9 @@ def post_validate_schema(cls, values: Dict) -> dict:
if not isinstance(data, dict):
raise Exception("`get_token` must return a `typing.Dict` type.")

values.__pydantic_extra__.update(data)
# a workaround for extra attributes since adding extra=allow in modelconfig adds `addition_props`
# field to the schema
values.__dict__.update(token_data=data)

if api_settings.UPDATE_LAST_LOGIN:
update_last_login(None, cls._user)
Expand All @@ -135,7 +137,9 @@ def post_validate_schema(cls, values: Dict) -> dict:

def to_response_schema(self):
_schema_type = self.get_response_schema()
return _schema_type(**self.dict(exclude={"password"}))
return _schema_type(
**self.dict(exclude={"password"}), **self.__dict__.get("token_data", {})
)


class TokenObtainPairOutputSchema(AuthUserSchema):
Expand Down

0 comments on commit 36ef232

Please sign in to comment.