rb-commons 0.5.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -267,6 +267,36 @@ class BaseManager(Generic[ModelType]):
267
267
  await self.session.flush()
268
268
  return await self._smart_commit(instance)
269
269
 
270
+ @with_transaction_error_handling
271
+ async def lazy_save(self, instance: ModelType, load_relations: Sequence[str] = None) -> Optional[ModelType]:
272
+ self.session.add(instance)
273
+ await self.session.flush()
274
+ await self._smart_commit(instance)
275
+
276
+ if load_relations is None:
277
+ mapper = inspect(self.model)
278
+ load_relations = [rel.key for rel in mapper.relationships]
279
+
280
+ if not load_relations:
281
+ return instance
282
+
283
+ stmt = select(self.model).filter_by(id=instance.id)
284
+
285
+ for rel in load_relations:
286
+ stmt = stmt.options(selectinload(getattr(self.model, rel)))
287
+
288
+ result = await self.session.execute(stmt)
289
+ loaded_instance = result.scalar_one_or_none()
290
+
291
+ if loaded_instance is None:
292
+ raise NotFoundException(
293
+ message="Object saved but could not be retrieved with relationships",
294
+ status=404,
295
+ code="0001",
296
+ )
297
+
298
+ return loaded_instance
299
+
270
300
  @with_transaction_error_handling
271
301
  async def update(self, instance: ModelType, **fields):
272
302
  if not fields:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rb-commons
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -11,7 +11,7 @@ rb_commons/http/consul.py,sha256=Ioq72VD1jGwoC96set7n2SgxN40olzI-myA2lwKkYi4,186
11
11
  rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
12
12
  rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
14
- rb_commons/orm/managers.py,sha256=Tk33tD4l94IkliHFBR_BRy-jrc-JgVh9S_mXn8v0rpM,13620
14
+ rb_commons/orm/managers.py,sha256=w0vTrGfugWDC1ccGU2b19DfGQ6_6X3CWMbBzkjpQiFs,14659
15
15
  rb_commons/orm/services.py,sha256=71eRcJ4TxZvzNz-hLXo12X4U7PGK54ZfbLAb27AjZi8,1589
16
16
  rb_commons/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  rb_commons/permissions/role_permissions.py,sha256=HL50s5RHW1nk2U3-YTESg0EDGkJDu1vN4QchcfK-L5g,988
@@ -20,7 +20,7 @@ rb_commons/schemes/jwt.py,sha256=F66JJDhholuOPPzlKeoC6f1TL4gXg4oRUrV5yheNpyo,167
20
20
  rb_commons/schemes/pagination.py,sha256=8VZW1wZGJIPR9jEBUgppZUoB4uqP8ORudHkMwvEJSxg,1866
21
21
  rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  rb_commons/utils/media.py,sha256=KNY_9SdRa3Rp7d3B1tZaXkhmzVa65RcS62BYwZP1bVM,332
23
- rb_commons-0.5.0.dist-info/METADATA,sha256=bT0B3meXrn9ME0juZhAq0XFg58MaAJxltKGBzpSHEjg,6570
24
- rb_commons-0.5.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
25
- rb_commons-0.5.0.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
26
- rb_commons-0.5.0.dist-info/RECORD,,
23
+ rb_commons-0.5.1.dist-info/METADATA,sha256=VDh2GcvBL_Uhvka30qhbR_MCnAcxjP-swb4OPhXyz6Q,6570
24
+ rb_commons-0.5.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
25
+ rb_commons-0.5.1.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
26
+ rb_commons-0.5.1.dist-info/RECORD,,