Skip to content

Commit

Permalink
Added debug print and use model_dump instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed Jul 26, 2024
1 parent f6f2a7f commit 0f281f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions gitlab_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def parse_pydantic_schema(schema):
to a dictionary containing SQLAlchemy models.
Only works if nested schemas have specified the Meta.orm_model.
"""
parsed_schema = dict(schema)
parsed_schema = schema.model_dump()
print(f"\nPARSED SCHEMA: {parsed_schema}\n")
for key, value in parsed_schema.items():
try:
if isinstance(value, list) and len(value):
Expand All @@ -67,7 +68,7 @@ def parse_pydantic_schema(schema):
if is_pydantic(value) and hasattr(value, "dict"):
value_dict = value.dict()
if value_dict is not None:
print(f"Parsed SCHEMA KEY: {parsed_schema[key]}\nVALUE DICT for ORM MODEL: {value_dict}")
print(f"\nParsed SCHEMA KEY: {parsed_schema[key]}\n\nVALUE DICT for ORM MODEL: {value_dict}\n")
parsed_schema[key] = value.Meta.orm_model(**value_dict)
except AttributeError:
raise AttributeError(
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ def agent_fixture():
def test_parse_pydantic_schema(fixture, request):
pydantic_model = request.getfixturevalue(fixture)
try:
parsed_schema = parse_pydantic_schema(pydantic_model.model_dump())
parsed_schema = parse_pydantic_schema(pydantic_model)
logger.debug(f"parsed_schema for {fixture}:\n{parsed_schema}\n")
sqlalchemy_model = pydantic_model.Meta.orm_model(**parsed_schema)
sqlalchemy_model_dict = {k: v for k, v in sqlalchemy_model.__dict__.items()}
Expand Down

0 comments on commit 0f281f8

Please sign in to comment.