Util
NOT_LOADED = NotLoaded()
module-attribute
NotSaved = T | NotLoaded
module-attribute
OptionallyLoaded = T | NotLoaded
module-attribute
PositiveInt = Annotated[int, AfterValidator(_is_positive)]
module-attribute
T = TypeVar('T')
module-attribute
ValidatedUTCDatetime = Annotated[datetime.datetime, AfterValidator(_assert_utc)]
module-attribute
ValidatedUUID = Annotated[UUID, BeforeValidator(_make_valid_uuid)]
module-attribute
logger = logging.getLogger(__name__)
module-attribute
NotLoaded
Bases: BaseModel
Placeholder for a relationship that has not been loaded.
Use this as a type hint for any attributes that correspond to relationships that may not be loaded (i.e. lazy='raise' in the relationship) This is to distinguish between None compared to a relationship that does exist but just wasn't loaded for this instance.
The UNLOADED instance below should be set as the value for any unloaded relationships
assert_utc_and_strip(dt, warning_only=False)
Ensure that a datetime has a UTC timezone then strip it.
Basically make sure that the time was tz aware, but don't store the tzinfo in the database.
ensure_uuid(uuid_or_str)
Ensures that a UUID is returned from either a string or a UUID.
Mostly necessary because sqlite doesn't have a native UUID type so it converts UUIDs to strings on commit.
Note: loading a model still returns UUID as appropriate, it's only when accessing variables after commit/flush that is a problem Args: uuid_or_str: