Skip to content

Commit 639414d

Browse files
committed
adding loguru.catch to functions to facilitate nested stderr messaging
1 parent 05d453c commit 639414d

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ distlib==0.3.7
2121
# via virtualenv
2222
filelock==3.13.1
2323
# via virtualenv
24-
identify==2.5.32
24+
identify==2.5.33
2525
# via pre-commit
2626
isort==5.12.0
2727
# via -r dev_requirements.in

sqlmodel_crud_utils/a_sync.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
upsert = get_sql_dialect_import(dialect=get_val("SQL_DIALECT"))
1717

1818

19+
@logger.catch
1920
async def get_result_from_query(query: SelectOfScalar, session: AsyncSession):
2021
"""
2122
Processes an SQLModel query object and returns a singular result from the
@@ -37,6 +38,7 @@ async def get_result_from_query(query: SelectOfScalar, session: AsyncSession):
3738
return results
3839

3940

41+
@logger.catch
4042
async def get_one_or_create(
4143
session_inst: AsyncSession,
4244
model: type[SQLModel],
@@ -86,6 +88,7 @@ async def _get_entry(sqlmodel, **key_args):
8688
return created, False
8789

8890

91+
@logger.catch
8992
async def write_row(data_row: Type[SQLModel], session_inst: AsyncSession):
9093
"""
9194
Writes a new instance of an SQLModel ORM model to the database, with an
@@ -110,6 +113,7 @@ async def write_row(data_row: Type[SQLModel], session_inst: AsyncSession):
110113
return False, None
111114

112115

116+
@logger.catch
113117
async def insert_data_rows(data_rows, session_inst: AsyncSession):
114118
try:
115119
session_inst.add_all(data_rows)
@@ -145,6 +149,7 @@ async def insert_data_rows(data_rows, session_inst: AsyncSession):
145149
return status, {"success": processed_rows, "failed": failed_rows}
146150

147151

152+
@logger.catch
148153
async def get_row(
149154
id_str: str or int,
150155
session_inst: AsyncSession,
@@ -172,6 +177,7 @@ async def get_row(
172177
return success, row
173178

174179

180+
@logger.catch
175181
async def get_rows(
176182
session_inst: AsyncSession,
177183
model: type[SQLModel],
@@ -244,6 +250,7 @@ async def get_rows(
244250
return success, results
245251

246252

253+
@logger.catch
247254
async def get_rows_within_id_list(
248255
id_str_list: list[str | int],
249256
session_inst: AsyncSession,
@@ -261,6 +268,7 @@ async def get_rows_within_id_list(
261268
return success, results
262269

263270

271+
@logger.catch
264272
async def delete_row(
265273
id_str: str or int,
266274
session_inst: AsyncSession,
@@ -290,6 +298,7 @@ async def delete_row(
290298
return success
291299

292300

301+
@logger.catch
293302
async def bulk_upsert_mappings(
294303
payload: list,
295304
session_inst: AsyncSession,
@@ -316,6 +325,7 @@ async def bulk_upsert_mappings(
316325
return False
317326

318327

328+
@logger.catch
319329
async def update_row(
320330
id_str: int | str,
321331
data: dict,

sqlmodel_crud_utils/sync.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
upsert = get_sql_dialect_import(dialect=get_val("SQL_DIALECT"))
1616

1717

18+
@logger.catch
1819
def get_result_from_query(query: SelectOfScalar, session: Session):
1920
"""
2021
Processes an SQLModel query object and returns a singular result from the
@@ -36,6 +37,7 @@ def get_result_from_query(query: SelectOfScalar, session: Session):
3637
return results
3738

3839

40+
@logger.catch
3941
def get_one_or_create(
4042
session_inst: Session,
4143
model: type[SQLModel],
@@ -85,6 +87,7 @@ def _get_entry(sqlmodel, **key_args):
8587
return created, False
8688

8789

90+
@logger.catch
8891
def write_row(data_row: Type[SQLModel], session_inst: Session):
8992
"""
9093
Writes a new instance of an SQLModel ORM model to the database, with an
@@ -109,6 +112,7 @@ def write_row(data_row: Type[SQLModel], session_inst: Session):
109112
return False, None
110113

111114

115+
@logger.catch
112116
def insert_data_rows(data_rows, session_inst: Session):
113117
try:
114118
session_inst.add_all(data_rows)
@@ -142,6 +146,7 @@ def insert_data_rows(data_rows, session_inst: Session):
142146
return status, {"success": processed_rows, "failed": failed_rows}
143147

144148

149+
@logger.catch
145150
def get_row(
146151
id_str: str or int,
147152
session_inst: Session,
@@ -169,6 +174,7 @@ def get_row(
169174
return success, row
170175

171176

177+
@logger.catch
172178
def get_rows(
173179
session_inst: Session,
174180
model: type[SQLModel],
@@ -241,6 +247,7 @@ def get_rows(
241247
return success, results
242248

243249

250+
@logger.catch
244251
def get_rows_within_id_list(
245252
id_str_list: list[str | int],
246253
session_inst: Session,
@@ -258,6 +265,7 @@ def get_rows_within_id_list(
258265
return success, results
259266

260267

268+
@logger.catch
261269
def delete_row(
262270
id_str: str or int,
263271
session_inst: Session,
@@ -287,6 +295,7 @@ def delete_row(
287295
return success
288296

289297

298+
@logger.catch
290299
def bulk_upsert_mappings(
291300
payload: list,
292301
session_inst: Session,
@@ -313,6 +322,7 @@ def bulk_upsert_mappings(
313322
return False
314323

315324

325+
@logger.catch
316326
def update_row(
317327
id_str: int | str,
318328
data: dict,

0 commit comments

Comments
 (0)