Compare commits

..

4 Commits

Author SHA1 Message Date
creyD
c903266ec4 Adjusted files for isort & autopep 2025-04-03 07:45:38 +00:00
vikynoah
910638e3a6 fix: get_object alter for async response filter (#44) 2025-04-03 09:45:09 +02:00
vikynoah
83dca59817 fix: BaseSchemaModelOUT alter (#43) 2025-04-02 09:58:36 +02:00
vikynoah
b80d26586d fix: Response model (#41)
* feat: Filter response fields

* changes

* changes

* import fix

* changes
2025-03-27 09:33:04 +01:00
3 changed files with 22 additions and 9 deletions

View File

@@ -50,16 +50,28 @@ def get_object_or_404(
selected_columns = [
getattr(db_class, field) for field in response_fields if hasattr(db_class, field)
]
query = select(*selected_columns).select_from(db_class)
query = select(*selected_columns).where(getattr(db_class, lookup_column) == id)
result = await db.execute(query)
row = result.first()
if row is None:
raise HTTPException(status_code=404, detail="The object does not exist.")
if hasattr(row, "_mapping"):
obj_dict = dict(row._mapping)
else:
obj_dict = {column.key: getattr(row, column.key) for column in selected_columns}
else:
query = select(db_class).filter(getattr(db_class, lookup_column) == id)
result = await db.execute(query)
obj = result.scalar_one_or_none()
if obj is None:
raise HTTPException(status_code=404, detail="The object does not exist.") # type: ignore
query = select(db_class).where(getattr(db_class, lookup_column) == id)
result = await db.execute(query)
row = result.scalar_one_or_none()
if row is None:
raise HTTPException(status_code=404, detail="The object does not exist.")
obj_dict = {k: v for k, v in row.__dict__.items() if not k.startswith("_")}
if expunge:
await db.expunge(obj)
return obj
await db.expunge(obj_dict)
return obj_dict
def _get_sync_object() -> T:
if response_fields:

View File

@@ -1 +1,2 @@
from .base import * # noqa
from .response_schema import * #noqa

View File

@@ -11,6 +11,6 @@ class BaseSchemaModelIN(BaseModel):
class BaseSchemaModelOUT(BaseSchemaModelIN):
id: UUID
id: UUID | str
created_at: datetime
updated_at: datetime