1
- from typing import TYPE_CHECKING
1
+ import logging
2
+ from typing import TYPE_CHECKING , Any
2
3
from uuid import UUID , uuid4
3
4
4
5
from sqlalchemy .orm import Mapped , declarative_mixin , mapped_column
18
19
uuid6 = uuid4 # type: ignore[assignment, unused-ignore]
19
20
uuid7 = uuid4 # type: ignore[assignment, unused-ignore]
20
21
22
+ logger = logging .getLogger ("advanced_alchemy" )
23
+
21
24
22
25
@declarative_mixin
23
26
class UUIDPrimaryKey (SentinelMixin ):
@@ -31,6 +34,11 @@ class UUIDPrimaryKey(SentinelMixin):
31
34
class UUIDv6PrimaryKey (SentinelMixin ):
32
35
"""UUID v6 Primary Key Field Mixin."""
33
36
37
+ def __init_subclass__ (cls , ** kwargs : Any ) -> None :
38
+ super ().__init_subclass__ (** kwargs )
39
+ if not UUID_UTILS_INSTALLED and not cls .__module__ .startswith ("advanced_alchemy" ): # pragma: no cover
40
+ logger .warning ("`uuid-utils` not installed, falling back to `uuid4` for UUID v6 generation." )
41
+
34
42
id : Mapped [UUID ] = mapped_column (default = uuid6 , primary_key = True )
35
43
"""UUID Primary key column."""
36
44
@@ -39,5 +47,10 @@ class UUIDv6PrimaryKey(SentinelMixin):
39
47
class UUIDv7PrimaryKey (SentinelMixin ):
40
48
"""UUID v7 Primary Key Field Mixin."""
41
49
50
+ def __init_subclass__ (cls , ** kwargs : Any ) -> None :
51
+ super ().__init_subclass__ (** kwargs )
52
+ if not UUID_UTILS_INSTALLED and not cls .__module__ .startswith ("advanced_alchemy" ): # pragma: no cover
53
+ logger .warning ("`uuid-utils` not installed, falling back to `uuid4` for UUID v7 generation." )
54
+
42
55
id : Mapped [UUID ] = mapped_column (default = uuid7 , primary_key = True )
43
56
"""UUID Primary key column."""
0 commit comments