ezKit 3.0.75__tar.gz → 3.0.76__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.75
3
+ Version: 3.0.76
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -515,7 +515,7 @@ class Database:
515
515
 
516
516
  Returns:
517
517
  未启用序列化时返回 `CursorResult` 或 `ScalarResult`;
518
- 启用时返回字典列表或标量列表;执行或结果处理失败时记录错误并返回 None。
518
+ 启用时返回字典列表或标量列表;语句不返回行时返回空列表;执行或结果处理失败时记录错误并返回 None。
519
519
  未序列化的结果在 Session 关闭后返回,需要注意其生命周期;
520
520
  如需在Session 生命周期外使用结果,应启用序列化。
521
521
  """
@@ -534,9 +534,17 @@ class Database:
534
534
 
535
535
  with self._get_db() as session:
536
536
 
537
- result: CursorResult | ScalarResult = (
538
- session.scalars(stmt, execution_params, **kwargs) if scalars else session.execute(stmt, execution_params, **kwargs)
539
- )
537
+ raw_result: CursorResult = session.execute(stmt, execution_params, **kwargs)
538
+
539
+ # 序列化前检查 returns_rows
540
+ # INSERT、DELETE 等无返回行的语句,
541
+ # 执行成功时,返回 [],不会再调用 .mappings().all() 或 .all(),避免触发 ResourceClosedError。
542
+ # 执行失败时,会触发 Exception,返回 None。
543
+ if serialize and not raw_result.returns_rows:
544
+ logger.success(f"{info} | success")
545
+ return []
546
+
547
+ result: CursorResult | ScalarResult = raw_result.scalars() if scalars else raw_result
540
548
 
541
549
  if serialize and isinstance(result, CursorResult):
542
550
  rows = result.mappings().all()
@@ -1058,7 +1066,7 @@ class AsyncDatabase:
1058
1066
 
1059
1067
  Returns:
1060
1068
  未启用序列化时返回 `CursorResult` 或 `ScalarResult`;
1061
- 启用时返回字典列表或标量列表;执行或结果处理失败时记录错误并返回 None。
1069
+ 启用时返回字典列表或标量列表;语句不返回行时返回空列表;执行或结果处理失败时记录错误并返回 None。
1062
1070
  未序列化的结果在 Session 关闭后返回,需要注意其生命周期;
1063
1071
  如需在Session 生命周期外使用结果,应启用序列化。
1064
1072
  """
@@ -1078,11 +1086,17 @@ class AsyncDatabase:
1078
1086
  async with self._get_db() as session:
1079
1087
 
1080
1088
  # AsyncSession.execute() 的类型标注较宽,运行时结果仍按 CursorResult 处理。
1081
- result: CursorResult | ScalarResult = (
1082
- await session.scalars(stmt, execution_params, **kwargs)
1083
- if scalars
1084
- else await session.execute(stmt, execution_params, **kwargs) # type: ignore
1085
- )
1089
+ raw_result: CursorResult = await session.execute(stmt, execution_params, **kwargs) # type: ignore
1090
+
1091
+ # 序列化前检查 returns_rows
1092
+ # INSERT、DELETE 等无返回行的语句,
1093
+ # 执行成功时,返回 [],不会再调用 .mappings().all() 或 .all(),避免触发 ResourceClosedError。
1094
+ # 执行失败时,会触发 Exception,返回 None。
1095
+ if serialize and not raw_result.returns_rows:
1096
+ logger.success(f"{info} | success")
1097
+ return []
1098
+
1099
+ result: CursorResult | ScalarResult = raw_result.scalars() if scalars else raw_result
1086
1100
 
1087
1101
  if serialize and isinstance(result, CursorResult):
1088
1102
  rows = result.mappings().all()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.75
3
+ Version: 3.0.76
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="3.0.75",
7
+ version="3.0.76",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes