fastapi-factory-utilities 0.4.2__py3-none-any.whl → 0.5.0__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.

Potentially problematic release.


This version of fastapi-factory-utilities might be problematic. Click here for more details.

@@ -2,7 +2,7 @@
2
2
 
3
3
  import logging
4
4
  from collections.abc import Sequence
5
- from typing import Any
5
+ from typing import NotRequired, TypedDict, Unpack
6
6
 
7
7
  from opentelemetry.trace import Span, get_current_span
8
8
  from opentelemetry.util.types import AttributeValue
@@ -11,42 +11,69 @@ from structlog.stdlib import BoundLogger, get_logger
11
11
  _logger: BoundLogger = get_logger()
12
12
 
13
13
 
14
+ class ExceptionParameters(TypedDict):
15
+ """Parameters for the exception."""
16
+
17
+ message: NotRequired[str]
18
+ level: NotRequired[int]
19
+
20
+
14
21
  class FastAPIFactoryUtilitiesError(Exception):
15
22
  """Base exception for the FastAPI Factory Utilities."""
16
23
 
17
24
  def __init__(
18
25
  self,
19
- *args: tuple[Any],
20
- message: str | None = None,
21
- level: int = logging.ERROR,
22
- **kwargs: dict[str, Any],
26
+ *args: object,
27
+ **kwargs: Unpack[ExceptionParameters],
23
28
  ) -> None:
24
- """Instanciate the exception.
29
+ """Instantiate the exception.
25
30
 
26
31
  Args:
27
- *args (Tuple[Any]): The arguments.
28
- message (str | None): The message.
29
- level (int): The logging level.
30
- **kwargs (dict[str, Any]): The keyword arguments
32
+ *args: The arguments.
33
+ message: The message.
34
+ level: The logging level.
35
+ **kwargs: The keyword arguments.
36
+
31
37
  """
38
+ # Extract the message and the level from the kwargs if they are present
39
+ self.message: str | None = kwargs.pop("message", None)
40
+ self.level: int = kwargs.pop("level", logging.ERROR)
41
+
42
+ # If the message is not present, try to extract it from the args
43
+ if self.message is None and len(args) > 0 and isinstance(args[0], str):
44
+ self.message = args[0]
45
+
32
46
  # Log the Exception
33
- if message:
34
- _logger.log(level=level, event=message)
35
- self.message = message
36
- self.level = level
37
- args = (message, *args) # type: ignore
38
- # Propagate the exception
39
- span: Span = get_current_span()
40
- # If not otel is setup, INVALID_SPAN is retrive from get_current_span
41
- # and it will respond False to the is_recording method
42
- if span.is_recording():
43
- span.record_exception(self)
44
- for key, value in kwargs.items():
45
- attribute_value: AttributeValue
46
- if not isinstance(value, (str, bool, int, float, Sequence)):
47
- attribute_value = str(value)
48
- else:
49
- attribute_value = value
50
- span.set_attribute(key, attribute_value)
47
+ if self.message:
48
+ _logger.log(level=self.level, event=self.message)
49
+
50
+ try:
51
+ # Propagate the exception
52
+ span: Span = get_current_span()
53
+ # If not otel is setup, INVALID_SPAN is retrieved from get_current_span
54
+ # and it will respond False to the is_recording method
55
+ if span.is_recording():
56
+ span.record_exception(self)
57
+ for key, value in kwargs.items():
58
+ attribute_value: AttributeValue
59
+ if not isinstance(value, (str, bool, int, float, Sequence)):
60
+ attribute_value = str(value)
61
+ else:
62
+ attribute_value = value
63
+ span.set_attribute(key, attribute_value)
64
+ except Exception: # pylint: disable=broad-exception-caught
65
+ # Suppress any errors that occur while propagating the exception
66
+ pass
67
+
51
68
  # Call the parent class
52
69
  super().__init__(*args)
70
+
71
+ def __str__(self) -> str:
72
+ """Return the string representation of the exception.
73
+
74
+ Returns:
75
+ str: The message if available, otherwise the default exception string.
76
+ """
77
+ if self.message is not None:
78
+ return self.message
79
+ return super().__str__()
@@ -1,8 +1,9 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: fastapi_factory_utilities
3
- Version: 0.4.2
3
+ Version: 0.5.0
4
4
  Summary: Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie, Httpx, AioPika and OpenTelemetry.
5
5
  License: MIT
6
+ License-File: LICENSE
6
7
  Keywords: python,fastapi,beanie,httpx,opentelemetry,microservices
7
8
  Author: miragecentury
8
9
  Author-email: victorien.vanroye@gmail.com
@@ -15,7 +15,7 @@ fastapi_factory_utilities/core/app/fastapi_builder.py,sha256=KoywPbWu9wY5s1KpBAw
15
15
  fastapi_factory_utilities/core/app/plugin_manager/__init__.py,sha256=hHk_fet3d41I-MzohGlvbNjqWQtAbxWaaEfbt41Zweo,319
16
16
  fastapi_factory_utilities/core/app/plugin_manager/exceptions.py,sha256=CFrZvROT7mLzNpXWwDra1j08lA_7ZrSrOHN94sEEfnQ,1026
17
17
  fastapi_factory_utilities/core/app/plugin_manager/plugin_manager.py,sha256=b6wDStsjAdCKExFFNCFEmeMERNsVCeIp1qseKfn5TO4,6681
18
- fastapi_factory_utilities/core/exceptions.py,sha256=HAd0RDJNBVc1NOcwfHQo_Xya8SCYuD9edynx3VKMYVs,1784
18
+ fastapi_factory_utilities/core/exceptions.py,sha256=9s-i_RHPCsOswQPRvK8tyy-smE1118pytxWDJMNEl0M,2670
19
19
  fastapi_factory_utilities/core/plugins/__init__.py,sha256=W-BCkqP0xG980980z3mc8T6Vrp1Akv4szA0PRzkUbiU,756
20
20
  fastapi_factory_utilities/core/plugins/example/__init__.py,sha256=GF69IygLXxzrCh7VryekEWun663kKBhWtRS3w-1tzBc,1030
21
21
  fastapi_factory_utilities/core/plugins/httpx_plugin/__init__.py,sha256=P5FUyv7mQr8RZWQ8ifkoK8GXvqSI71q2b2dm-ag2JhQ,1028
@@ -76,8 +76,8 @@ fastapi_factory_utilities/example/models/books/repository.py,sha256=7K63uAsSEGZ2
76
76
  fastapi_factory_utilities/example/services/books/__init__.py,sha256=Z06yNRoA7Zg3TGN-Q9rrvJg6Bbx-qJw661MVwukV6vQ,148
77
77
  fastapi_factory_utilities/example/services/books/services.py,sha256=-x7d4hotUWLzWo5uImMjFmtNcSTHwWv2bfttIbYYKbA,5380
78
78
  fastapi_factory_utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
79
- fastapi_factory_utilities-0.4.2.dist-info/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
80
- fastapi_factory_utilities-0.4.2.dist-info/METADATA,sha256=TQga1orWq9y3GXz54xm-7WkZRX-8gAl-iWJ3g7XE3lM,3478
81
- fastapi_factory_utilities-0.4.2.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
82
- fastapi_factory_utilities-0.4.2.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
83
- fastapi_factory_utilities-0.4.2.dist-info/RECORD,,
79
+ fastapi_factory_utilities-0.5.0.dist-info/METADATA,sha256=8f6MuYLqieqLs4cFDZ8a75dO4zmdcqVUDsYPb3wkP4k,3500
80
+ fastapi_factory_utilities-0.5.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
81
+ fastapi_factory_utilities-0.5.0.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
82
+ fastapi_factory_utilities-0.5.0.dist-info/licenses/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
83
+ fastapi_factory_utilities-0.5.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.3
2
+ Generator: poetry-core 2.2.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any