Skip to content

Commit 10b94b8

Browse files
committed
style fix
1 parent d9b5e5f commit 10b94b8

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

fastapi_crudrouter/core/sqlalchemy.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
update_route: Union[bool, DEPENDENCIES] = True,
4343
delete_one_route: Union[bool, DEPENDENCIES] = True,
4444
delete_all_route: Union[bool, DEPENDENCIES] = True,
45-
**kwargs: Any
45+
**kwargs: Any,
4646
) -> None:
4747
assert (
4848
sqlalchemy_installed
@@ -66,7 +66,7 @@ def __init__(
6666
update_route=update_route,
6767
delete_one_route=delete_one_route,
6868
delete_all_route=delete_all_route,
69-
**kwargs
69+
**kwargs,
7070
)
7171

7272
def _get_all(self, *args: Any, **kwargs: Any) -> CALLABLE_LIST:
@@ -100,7 +100,6 @@ def route(
100100

101101
return route
102102

103-
104103
def _get_orm_object(self, db: Session, orm_model: Model, model: Model) -> Any:
105104
query = db.query(orm_model)
106105
filter_items = 0
@@ -110,10 +109,9 @@ def _get_orm_object(self, db: Session, orm_model: Model, model: Model) -> Any:
110109
query = query.filter(column(key) == val)
111110
if filter_items == 0:
112111
raise Exception("No attributes for filter found")
113-
return query.one()
114-
112+
return query.one()
115113

116-
def _get_orm_object_or_value(self, db: Session, val: Any) -> Any:
114+
def _get_orm_object_or_value(self, db: Session, val: Any) -> Any:
117115
"""Return an inflated database object or a plain value.
118116
119117
If a `val` is a SqlModel type and has defined a Meta.orm model
@@ -133,16 +131,14 @@ def _get_orm_object_or_value(self, db: Session, val: Any) -> Any:
133131
return self._get_orm_object(db, orm_model, val)
134132
return val
135133

136-
137134
def _create(self, *args: Any, **kwargs: Any) -> CALLABLE:
138-
139135
def route(
140136
model: self.create_schema, # type: ignore
141137
db: Session = Depends(self.db_func),
142138
) -> Model:
143139
try:
144140
db_model: Model = self.db_model()
145-
141+
146142
for key, val in model:
147143
if val:
148144
setattr(db_model, key, self._get_orm_object_or_value(db, val))
@@ -169,7 +165,9 @@ def route(
169165
for key, val in model:
170166
if key != self._pk:
171167
if hasattr(db_model, key):
172-
setattr(db_model, key, self._get_orm_object_or_value(db, val))
168+
setattr(
169+
db_model, key, self._get_orm_object_or_value(db, val)
170+
)
173171

174172
db.commit()
175173
db.refresh(db_model)

tests/test_sqlalchemy_nested_obj.py

-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def test_get():
172172
session.commit()
173173
session.refresh(hero)
174174

175-
176175
res = client.get(HEROES_URL)
177176
assert res.status_code == 200
178177
assert res.json() == [{**HeroRead(**object_as_dict(hero)).dict()}]

0 commit comments

Comments
 (0)