StrictModel¶
StrictModel keeps the same ORM API as Model, but tightens runtime behavior.
What changes compared to Model¶
StrictModel adds two important guarantees:
- scalar field assignments are validated immediately
- undeclared public attributes raise
AttributeError
That makes it a good fit when you want Saffier's ORM without the looser Python object behavior of the default model class.
Practical example¶
class Product(saffier.StrictModel):
id = saffier.IntegerField(primary_key=True, autoincrement=True)
name = saffier.CharField(max_length=100)
rating = saffier.IntegerField(minimum=1, maximum=5, default=1)
class Meta:
registry = models
product = Product(name="Tea", rating=5)
product.rating = 6 # raises ValidationError
product.unknown = "value" # raises AttributeError
What it does not change¶
StrictModel does not change query semantics, registry behavior, relation
loading, or migration output. It is a runtime discipline layer over the normal
Saffier model lifecycle.
saffier.StrictModel
¶
StrictModel(*model_refs, **kwargs)
Bases: Model
Model variant that validates assignments and forbids ad-hoc public attributes.
StrictModel is useful when you want the Saffier ORM surface but prefer a
more defensive runtime model that rejects undeclared attributes and validates
scalar assignments immediately instead of waiting until persistence time.
Source code in saffier/core/db/models/base.py
76 77 78 79 80 81 82 | |
pk
property
writable
¶
pk
Return the model primary key in scalar or mapping form.
Single-column primary keys are returned as the raw value. Composite
primary keys are returned as a mapping from logical field name to value,
unless every component is None, in which case None is returned.
identifying_db_fields
cached
property
¶
identifying_db_fields
Returns the database columns that uniquely identify the current instance.
Saffier currently uses the model primary key columns for this.
can_load
property
¶
can_load
Return whether the instance can be reloaded from the database.
The instance must belong to a concrete registered model and expose all identifying database fields.
Meta
¶
get_admin_marshall_config
classmethod
¶
get_admin_marshall_config(*, phase, for_schema)
Source code in saffier/core/db/models/mixins/admin.py
12 13 14 15 16 17 18 19 20 21 22 | |
get_admin_marshall_class
classmethod
¶
get_admin_marshall_class(*, phase, for_schema=False)
Source code in saffier/core/db/models/mixins/admin.py
24 25 26 27 28 29 30 31 32 33 34 | |
get_admin_marshall_for_save
classmethod
¶
get_admin_marshall_for_save(instance=None, /, **kwargs)
Source code in saffier/core/db/models/mixins/admin.py
36 37 38 39 40 41 42 | |
declarative
classmethod
¶
declarative()
Return the generated SQLAlchemy declarative model class.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
typing.Any: Declarative SQLAlchemy model created from the Saffier |
Any
|
model definition. |
Source code in saffier/core/db/models/mixins/generics.py
15 16 17 18 19 20 21 22 23 | |
generate_model_declarative
classmethod
¶
generate_model_declarative()
Transform the Saffier table into a SQLAlchemy declarative model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
typing.Any: Declarative model class bound to the same SQLAlchemy |
Any
|
table. |
Source code in saffier/core/db/models/mixins/generics.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
_update_auto_now_fields
¶
_update_auto_now_fields(values, fields)
Refresh auto_now date and datetime fields inside a payload.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Updated payload dictionary.
TYPE:
|
Source code in saffier/core/utils/models.py
29 30 31 32 33 34 35 36 37 38 | |
_resolve_value
¶
_resolve_value(value)
Normalize one value for storage or query generation.
Dictionaries are JSON-encoded, enums are converted to their member names, and every other value is returned unchanged.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Raw value supplied by model or queryset code.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
typing.Any: Normalized value suitable for downstream processing. |
Source code in saffier/core/utils/models.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
_is_model_ref_instance
staticmethod
¶
_is_model_ref_instance(value)
Source code in saffier/core/db/models/base.py
84 85 86 87 88 89 90 | |
resolve_model_ref_field_name
classmethod
¶
resolve_model_ref_field_name(ref_type)
Return the RefForeignKey field that accepts ref_type references.
| PARAMETER | DESCRIPTION |
|---|---|
ref_type
|
Concrete
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Name of the field that can store references of this type.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ModelReferenceError
|
If no |
Source code in saffier/core/db/models/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
merge_model_refs
classmethod
¶
merge_model_refs(model_refs, kwargs=None)
Merge positional ModelRef objects into a keyword payload.
Saffier reserves positional constructor arguments for model reference
objects so callers can write Article(tag_ref, author_ref, title="...")
and still end up with a normal keyword payload keyed by the owning
RefForeignKey fields.
| PARAMETER | DESCRIPTION |
|---|---|
model_refs
|
Positional constructor arguments.
TYPE:
|
kwargs
|
Existing keyword payload.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized keyword payload including merged model |
dict[str, Any]
|
references. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If any positional argument is not a model reference instance. |
Source code in saffier/core/db/models/base.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
setup_model_fields_from_kwargs
¶
setup_model_fields_from_kwargs(model_refs, kwargs)
Normalize constructor input and assign values onto the instance.
Positional ModelRef arguments are merged into the keyword payload,
composite or virtual inputs are expanded through field hooks, and each
resulting value is assigned using normal model attribute semantics so
relation-aware setters still run.
| PARAMETER | DESCRIPTION |
|---|---|
model_refs
|
Positional model-reference objects.
TYPE:
|
kwargs
|
Raw keyword payload supplied to the constructor.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Normalized payload after assignment.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the payload contains unknown public attributes. |
Source code in saffier/core/db/models/base.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_plain_model_fields
classmethod
¶
get_plain_model_fields()
Source code in saffier/core/db/models/base.py
202 203 204 | |
_matches_plain_annotation
classmethod
¶
_matches_plain_annotation(annotation, value)
Source code in saffier/core/db/models/base.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
validate_plain_field_value
classmethod
¶
validate_plain_field_value(key, value)
Source code in saffier/core/db/models/base.py
238 239 240 241 242 243 244 245 246 | |
normalize_field_kwargs
classmethod
¶
normalize_field_kwargs(kwargs=None)
Normalize constructor or persistence payloads through field hooks.
Every field may rewrite or expand incoming values before validation. This is how composite fields, foreign keys, and other virtual helpers expose a convenient high-level API while still producing a concrete payload.
| PARAMETER | DESCRIPTION |
|---|---|
kwargs
|
Input payload keyed by logical field name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Normalized payload. |
Source code in saffier/core/db/models/base.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
get_model_engine_name
classmethod
¶
get_model_engine_name()
Return the configured engine name for the model, if any.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Explicit model engine name, inherited registry default,
or |
Source code in saffier/core/db/models/base.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
get_model_engine
classmethod
¶
get_model_engine()
Resolve and return the configured engine adapter for the model.
Source code in saffier/core/db/models/base.py
286 287 288 289 290 291 292 293 294 | |
require_model_engine
classmethod
¶
require_model_engine()
Return the model engine or raise when none is configured.
Source code in saffier/core/db/models/base.py
296 297 298 299 300 301 302 | |
get_engine_model_class
classmethod
¶
get_engine_model_class(*, mode='projection')
Return the engine-backed class for the model.
Source code in saffier/core/db/models/base.py
304 305 306 307 | |
engine_validate
classmethod
¶
engine_validate(value, *, mode='validation')
Validate external data through the configured engine adapter.
Source code in saffier/core/db/models/base.py
309 310 311 312 | |
from_engine
classmethod
¶
from_engine(value, *, exclude_unset=True)
Build a Saffier model instance from an engine-backed value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Engine-backed object or input payload accepted by the engine.
TYPE:
|
exclude_unset
|
Whether engine defaults absent from the original input should be omitted from the Saffier constructor payload.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
New Saffier model instance.
TYPE:
|
Source code in saffier/core/db/models/base.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
engine_json_schema
classmethod
¶
engine_json_schema(*, mode='projection', **kwargs)
Return the engine-generated JSON schema for the model.
Source code in saffier/core/db/models/base.py
333 334 335 336 | |
to_engine_model
¶
to_engine_model(
*, include=None, exclude=None, exclude_none=False
)
Project the current instance into the configured engine model.
Source code in saffier/core/db/models/base.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
engine_dump
¶
engine_dump(
*, include=None, exclude=None, exclude_none=False
)
Serialize the engine-backed projection of the current instance.
Source code in saffier/core/db/models/base.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
engine_dump_json
¶
engine_dump_json(
*, include=None, exclude=None, exclude_none=False
)
Serialize the engine-backed projection of the current instance to JSON.
Source code in saffier/core/db/models/base.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
_persist_model_references
async
¶
_persist_model_references(field_names=None)
Persist staged RefForeignKey values after a successful save.
| PARAMETER | DESCRIPTION |
|---|---|
field_names
|
Optional subset of reference fields to persist.
TYPE:
|
Source code in saffier/core/db/models/base.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
_persist_related_fields
async
¶
_persist_related_fields(field_names=None)
Persist staged reverse-relation values after the model is saved.
| PARAMETER | DESCRIPTION |
|---|---|
field_names
|
Optional subset of reverse relation names to flush.
TYPE:
|
Source code in saffier/core/db/models/base.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
_normalize_identifier_value
staticmethod
¶
_normalize_identifier_value(value)
Source code in saffier/core/db/models/base.py
426 427 428 429 430 | |
_pk_values
¶
_pk_values()
Source code in saffier/core/db/models/base.py
432 433 434 435 436 | |
_instance_transaction
¶
_instance_transaction(*, force_rollback=False, **kwargs)
Source code in saffier/core/db/models/base.py
438 439 | |
join_identifiers_to_string
¶
join_identifiers_to_string(*, sep=', ', sep_inner='=')
Source code in saffier/core/db/models/base.py
490 491 492 493 494 495 | |
get_real_class
classmethod
¶
get_real_class()
Source code in saffier/core/db/models/base.py
521 522 523 524 525 | |
create_model_key
¶
create_model_key()
Create a stable identity tuple for recursion guards.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
tuple[Any, ...]: Tuple containing the model class and identifying |
...
|
values. |
Source code in saffier/core/db/models/base.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
identifying_clauses
¶
identifying_clauses(*, table=None, fields=None)
Build equality clauses that uniquely identify the current instance.
| PARAMETER | DESCRIPTION |
|---|---|
table
|
Optional table object to target instead of the active instance table.
TYPE:
|
fields
|
Optional subset of identifying fields to include.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Any]
|
list[Any]: SQLAlchemy boolean expressions suitable for |
Source code in saffier/core/db/models/base.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
_has_loaded_db_fields
¶
_has_loaded_db_fields()
Source code in saffier/core/db/models/base.py
595 596 597 598 599 600 | |
get_active_class_schema
classmethod
¶
get_active_class_schema()
Return the schema pinned directly on the model class.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Class-level schema override, if present. |
Source code in saffier/core/db/models/base.py
602 603 604 605 606 607 608 609 | |
get_active_instance_schema
¶
get_active_instance_schema()
Return the schema currently active for this instance.
Instance-level overrides win over cached table schema, which in turn wins over the class-level override.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
str | None: Active schema for this instance. |
Source code in saffier/core/db/models/base.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
load_recursive
async
¶
load_recursive(
only_needed=False, only_needed_nest=False, _seen=None
)
Load the instance and recurse through already-linked FK relations.
The method is careful to avoid infinite loops by tracking visited model identities while traversing the object graph.
| PARAMETER | DESCRIPTION |
|---|---|
only_needed
|
Whether to skip reloading when DB-backed fields are already populated.
TYPE:
|
only_needed_nest
|
Whether nested relations should stop after the current object was already fully loaded.
TYPE:
|
_seen
|
Internal recursion guard keyed by model identity.
TYPE:
|
Source code in saffier/core/db/models/base.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
get_instance_name
¶
get_instance_name()
Return the lowercase class name used by relation helpers.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Lowercase model class name.
TYPE:
|
Source code in saffier/core/db/models/base.py
670 671 672 673 674 675 676 | |
_copy_model_definitions
classmethod
¶
_copy_model_definitions(
*, registry=None, unlink_same_registry=True
)
Copy fields and managers for dynamic model cloning.
Relation fields may be rewritten as string references when the target registry is still under construction so copied models do not retain live references back into the source registry.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Optional destination registry receiving the copy.
TYPE:
|
unlink_same_registry
|
Whether relations inside the same source registry should be rewritten as string references.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Definitions suitable for dynamic model creation. |
Source code in saffier/core/db/models/base.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 | |
copy_saffier_model
classmethod
¶
copy_saffier_model(
registry=None,
name="",
unlink_same_registry=True,
on_conflict="error",
)
Create a detached copy of the model class with copied field state.
The copy is used by migration preparation, proxy generation, and tests that need to attach the same logical model definition to another registry. Field instances are copied so later mutations on the copied model do not leak back into the original model definition.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Optional registry to immediately attach the copied model to.
TYPE:
|
name
|
Optional replacement class name.
TYPE:
|
unlink_same_registry
|
Whether same-registry relations should be rewritten as string references during the copy.
TYPE:
|
on_conflict
|
Conflict strategy used if
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The detached or newly attached copied model class. |
Source code in saffier/core/db/models/base.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |
real_add_to_registry
classmethod
¶
real_add_to_registry(
*,
registry,
name="",
database="keep",
on_conflict="error",
)
Attach a copied model class to another registry.
This is the internal implementation behind add_to_registry(). It
resolves naming conflicts, rebinds fields and managers to the target
registry, rebuilds relation descriptors, and regenerates the proxy model
so the attached class behaves like a first-class registered model.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Target registry.
TYPE:
|
name
|
Optional replacement model name.
TYPE:
|
database
|
Database binding strategy or explicit database object.
TYPE:
|
on_conflict
|
Conflict strategy for duplicate model names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The attached model class. |
| RAISES | DESCRIPTION |
|---|---|
ImproperlyConfigured
|
If a conflicting model already exists and the
conflict strategy is |
Source code in saffier/core/db/models/base.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
add_to_registry
classmethod
¶
add_to_registry(
registry,
name="",
database="keep",
*,
on_conflict="error",
)
Attach the model to another registry, copying if required.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
Destination registry.
TYPE:
|
name
|
Optional replacement model name.
TYPE:
|
database
|
Database rebinding strategy.
TYPE:
|
on_conflict
|
Conflict strategy for duplicate model names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: Registered model class. |
Source code in saffier/core/db/models/base.py
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | |
generate_proxy_model
classmethod
¶
generate_proxy_model()
Generate the lightweight proxy model used for SQLAlchemy-style access.
Proxy models mirror the field layout of the concrete model but stay detached from registry registration. They exist so class-level field access can emulate SQLAlchemy's declarative attribute style.
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: Proxy model class for |
Source code in saffier/core/db/models/base.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 | |
build
classmethod
¶
build(schema=None)
Build the SQLAlchemy table for the model in the requested schema.
Table generation expands multi-column fields, applies field-level global
constraints, attaches Meta-declared indexes and constraints, and keeps
schema-specific tables isolated from the shared registry metadata.
| PARAMETER | DESCRIPTION |
|---|---|
schema
|
Schema name to build against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Table
|
sqlalchemy.Table: Built or cached SQLAlchemy table for the model. |
Source code in saffier/core/db/models/base.py
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |
_get_unique_constraints
classmethod
¶
_get_unique_constraints(columns)
Returns the unique constraints for the model.
The columns must be a a list, tuple of strings or a UniqueConstraint object.
Source code in saffier/core/db/models/base.py
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | |
_get_indexes
classmethod
¶
_get_indexes(index)
Build a SQLAlchemy index from a Saffier Index declaration.
| PARAMETER | DESCRIPTION |
|---|---|
index
|
Declared Saffier index definition.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Index | None
|
sqlalchemy.Index | None: SQLAlchemy index object. |
Source code in saffier/core/db/models/base.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 | |
_expand_constraint_field_names
classmethod
¶
_expand_constraint_field_names(names)
Source code in saffier/core/db/models/base.py
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | |
update_from_dict
¶
update_from_dict(dict_values)
Assign values from a dictionary using normal attribute semantics.
| RETURNS | DESCRIPTION |
|---|---|
Self
|
The current instance for fluent usage.
TYPE:
|
Source code in saffier/core/db/models/base.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 | |
extract_db_fields
¶
extract_db_fields(only=None)
Collect persisted field values from the current instance.
| PARAMETER | DESCRIPTION |
|---|---|
only
|
Optional subset of logical field names to include.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Payload containing only database-backed fields. |
Source code in saffier/core/db/models/base.py
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
extract_column_values
classmethod
¶
extract_column_values(
extracted_values,
is_update=False,
is_partial=False,
phase="",
instance=None,
model_instance=None,
evaluate_values=False,
)
Convert logical field payloads into database column payloads.
The method runs field-specific normalization, expands multi-column fields such as composite foreign keys, injects defaults when allowed, and returns the final column-value mapping used by insert/update expressions.
| PARAMETER | DESCRIPTION |
|---|---|
extracted_values
|
Logical field payload keyed by Saffier field name.
TYPE:
|
is_update
|
Whether the payload is for an update operation.
TYPE:
|
is_partial
|
Whether the update payload omits untouched fields.
TYPE:
|
phase
|
Context label exposed to field hooks through context vars.
TYPE:
|
instance
|
Instance currently being persisted.
TYPE:
|
model_instance
|
Original model instance used by nested helpers.
TYPE:
|
evaluate_values
|
Whether callable payload values should be executed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Database-ready payload keyed by SQL column name. |
Source code in saffier/core/db/models/base.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 | |
__get_instance_values
¶
__get_instance_values(instance)
Source code in saffier/core/db/models/base.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | |
__eq__
¶
__eq__(other)
Source code in saffier/core/db/models/base.py
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | |
_row_value
staticmethod
¶
_row_value(row, key)
Return one value from a SQLAlchemy row mapping.
The SQLAlchemy result API may expose values either through the row's mapping interface or as attributes. This helper hides that difference so higher-level row loaders can ask for one key without caring how the result object was produced.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
SQLAlchemy row produced by a compiled query.
TYPE:
|
key
|
Column or label name to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Resolved value, or
TYPE:
|
Source code in saffier/core/db/models/row.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
_table_row_value
classmethod
¶
_table_row_value(row, table, key)
Resolve a row value using table-column objects when available.
Joined queries may store row data under SQLAlchemy Column objects
instead of plain string keys. This helper first tries the concrete table
column and falls back to the generic key lookup used by _row_value.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
SQLAlchemy row produced by a query.
TYPE:
|
table
|
SQLAlchemy table-like object exposing
TYPE:
|
key
|
Column key to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Value associated with the requested column, or
TYPE:
|
Any
|
row does not contain it. |
Source code in saffier/core/db/models/row.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
_build_related_pk_filter
classmethod
¶
_build_related_pk_filter(path, row, model_class)
Build a queryset filter targeting one related object's primary key.
Prefetch helpers need a deterministic filter payload for related
lookups, even when the related model has a composite primary key. This
method expands the supplied path into one path__pk_field=value entry
per primary-key column.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Lookup prefix leading to the related model.
TYPE:
|
row
|
Source row containing the root primary-key values.
TYPE:
|
model_class
|
Model class or instance exposing
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Keyword arguments suitable for queryset filtering. |
Source code in saffier/core/db/models/row.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
apply_prefetch_related
async
classmethod
¶
apply_prefetch_related(row, model, prefetch_related)
Apply prefetch directives to an already materialized model instance.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
Source row used to derive relation filters.
TYPE:
|
model
|
Model instance returned by row materialization.
TYPE:
|
prefetch_related
|
Prefetch directives attached to the queryset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The same model instance after all prefetch targets have |
type[Model]
|
been attached. |
Source code in saffier/core/db/models/row.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
from_query_result
classmethod
¶
from_query_result(
row,
select_related=None,
prefetch_related=None,
is_only_fields=False,
only_fields=None,
is_defer_fields=False,
exclude_secrets=False,
using_schema=None,
reference_select=None,
tables_and_models=None,
root_model_class=None,
prefix="",
)
Convert one SQLAlchemy result row into a Saffier model instance.
The loader reconstructs the requested object graph in three phases:
nested select_related branches are materialized first, local
foreign-key placeholders are populated next, and finally the base model
fields are copied from the row. Optional only(), defer(),
reference_select(), secret-field exclusion, and schema overrides are
all handled during the same pass so downstream queryset code receives a
fully consistent model instance.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
SQLAlchemy row returned by the executed query.
TYPE:
|
select_related
|
Related paths that were joined into the query and should be materialized recursively.
TYPE:
|
prefetch_related
|
Deferred prefetch instructions to apply after the base instance exists.
TYPE:
|
is_only_fields
|
Whether the row was produced by an
TYPE:
|
only_fields
|
Explicit field subset requested
by
TYPE:
|
is_defer_fields
|
Whether the row omits deferred fields.
TYPE:
|
exclude_secrets
|
Whether secret fields should be left unloaded on the resulting model.
TYPE:
|
using_schema
|
Schema override applied to generated table lookups and related instances.
TYPE:
|
reference_select
|
Extra row aliases to copy onto the model or nested related objects.
TYPE:
|
tables_and_models
|
Mapping produced by queryset compilation for joined table aliases.
TYPE:
|
root_model_class
|
Root model being materialized when recursion traverses into nested related models.
TYPE:
|
prefix
|
Prefix identifying the current join branch inside
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model] | None
|
type[Model] | None: Materialized model instance, or |
type[Model] | None
|
nested branch cannot be populated from the row. |
Source code in saffier/core/db/models/row.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
__apply_reference_select
classmethod
¶
__apply_reference_select(
model,
row,
references,
tables_and_models,
root_model_class,
using_schema=None,
)
Copy reference_select() aliases from a row onto the model tree.
reference_select() can target local attributes or nested related
objects. Nested dictionaries mirror the object graph and are traversed
recursively until a concrete row source is found.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Materialized model instance to mutate.
TYPE:
|
row
|
Row containing the selected values.
TYPE:
|
references
|
Mapping produced by queryset compilation for reference selections.
TYPE:
|
tables_and_models
|
Joined-table lookup map used to resolve nested sources.
TYPE:
|
root_model_class
|
Root model for fallback column resolution.
TYPE:
|
using_schema
|
Optional schema override for table lookup.
TYPE:
|
Source code in saffier/core/db/models/row.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
__resolve_reference_source
classmethod
¶
__resolve_reference_source(
row,
source,
tables_and_models,
root_model_class,
using_schema=None,
)
Resolve one reference_select() source from the current row.
The source may already be a row key, a SQLAlchemy column-like object, or a double-underscore path pointing at a joined table column.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
SQLAlchemy row containing the selected values.
TYPE:
|
source
|
Raw source token stored in the reference-select map.
TYPE:
|
tables_and_models
|
Joined-table lookup map used for path-based resolution.
TYPE:
|
root_model_class
|
Root model used when a direct table lookup is required.
TYPE:
|
using_schema
|
Optional schema override for table lookup.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Resolved value copied onto the model instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If the source cannot be resolved from the row. |
Source code in saffier/core/db/models/row.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
__resolve_reference_column
classmethod
¶
__resolve_reference_column(
source,
tables_and_models,
root_model_class,
using_schema=None,
)
Resolve a string reference-select source into a SQLAlchemy column.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Column name or
TYPE:
|
tables_and_models
|
Joined-table lookup map keyed by queryset prefixes.
TYPE:
|
root_model_class
|
Root model used when no joined table is specified.
TYPE:
|
using_schema
|
Optional schema override for table lookup.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any | None
|
Any | None: Resolved SQLAlchemy column object, or |
Any | None
|
column is not available. |
Source code in saffier/core/db/models/row.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
__apply_schema
classmethod
¶
__apply_schema(model, schema=None)
Attach a schema-specific table to one model instance when needed.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Model class or instance being prepared.
TYPE:
|
schema
|
Schema name requested by the queryset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The original |
type[Model]
|
table rebound to a schema-specific version. |
Source code in saffier/core/db/models/row.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
__should_ignore_related_name
classmethod
¶
__should_ignore_related_name(related_name, select_related)
Return whether a foreign-key placeholder is covered by select_related.
When a joined related object is already being materialized recursively, the loader must not also inject the lighter foreign-key placeholder for the same attribute. Doing so would overwrite the fully populated related instance.
| PARAMETER | DESCRIPTION |
|---|---|
related_name
|
Foreign-key attribute currently being evaluated.
TYPE:
|
select_related
|
Joined relation paths attached to the queryset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in saffier/core/db/models/row.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
__handle_prefetch_related
classmethod
¶
__handle_prefetch_related(
row,
model,
prefetch_related,
parent_cls=None,
original_prefetch=None,
is_nested=False,
)
Populate prefetched relations for one materialized model instance.
The synchronous implementation is used when row materialization already
runs inside sync-only code paths. It resolves plain relations,
many-to-many paths, and nested prefetch chains while guarding against
to_attr collisions on the destination model.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
Source row containing the root primary-key values.
TYPE:
|
model
|
Materialized model instance to enrich.
TYPE:
|
prefetch_related
|
Prefetch directives attached to the queryset.
TYPE:
|
parent_cls
|
Parent object for nested traversal.
TYPE:
|
original_prefetch
|
Root prefetch object preserved while recursion walks nested paths.
TYPE:
|
is_nested
|
Whether the current call is processing a nested branch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The same model instance with prefetched attributes set. |
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If |
Source code in saffier/core/db/models/row.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
__handle_prefetch_related_async
async
classmethod
¶
__handle_prefetch_related_async(
row,
model,
prefetch_related,
parent_cls=None,
original_prefetch=None,
is_nested=False,
)
Async variant of __handle_prefetch_related.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
Source row containing the root primary-key values.
TYPE:
|
model
|
Materialized model instance to enrich.
TYPE:
|
prefetch_related
|
Prefetch directives attached to the queryset.
TYPE:
|
parent_cls
|
Parent object for nested traversal.
TYPE:
|
original_prefetch
|
Root prefetch object preserved while recursion walks nested paths.
TYPE:
|
is_nested
|
Whether the current call is processing a nested branch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model]
|
type[Model]: The same model instance with prefetched attributes set. |
| RAISES | DESCRIPTION |
|---|---|
QuerySetError
|
If |
Source code in saffier/core/db/models/row.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
__process_nested_prefetch_related
classmethod
¶
__process_nested_prefetch_related(
row,
prefetch_related,
parent_cls,
original_prefetch,
queryset,
)
Resolve one nested reverse-relation prefetch synchronously.
Nested prefetches such as "team__members" need to be rewritten into a
queryset filter rooted at the child model. This helper derives the child
foreign-key path, injects the current parent primary-key values, and
executes the resulting queryset.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
Source row containing the current parent identifiers.
TYPE:
|
prefetch_related
|
Current nested prefetch branch.
TYPE:
|
parent_cls
|
Parent model instance used to derive the related filter.
TYPE:
|
original_prefetch
|
Root prefetch declaration from the queryset.
TYPE:
|
queryset
|
Queryset used to load the related records.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[type[Model]]
|
list[type[Model]]: Prefetched related records for the current branch. |
Source code in saffier/core/db/models/row.py
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
__process_nested_prefetch_related_async
async
classmethod
¶
__process_nested_prefetch_related_async(
row,
prefetch_related,
parent_cls,
original_prefetch,
queryset,
)
Async variant of __process_nested_prefetch_related.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
Source row containing the current parent identifiers.
TYPE:
|
prefetch_related
|
Current nested prefetch branch.
TYPE:
|
parent_cls
|
Parent model instance used to derive the related filter.
TYPE:
|
original_prefetch
|
Root prefetch declaration from the queryset.
TYPE:
|
queryset
|
Queryset used to load the related records.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[type[Model]]
|
list[type[Model]]: Prefetched related records for the current branch. |
Source code in saffier/core/db/models/row.py
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
__collect_prefetch_records
async
classmethod
¶
__collect_prefetch_records(
model, related_name, queryset=None
)
Collect prefetched records reachable through an attribute path.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Root model instance that already exists.
TYPE:
|
related_name
|
Relation path, including nested
TYPE:
|
queryset
|
Optional queryset used to constrain the collected records by primary key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[type[Model]]
|
list[type[Model]]: Related records discovered through the path. When |
list[type[Model]]
|
|
list[type[Model]]
|
filtered to the discovered primary keys. |
Source code in saffier/core/db/models/row.py
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | |
__traverse_prefetch_path
async
classmethod
¶
__traverse_prefetch_path(model, path_parts)
Traverse a relation path on an already materialized model tree.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Current model instance being inspected.
TYPE:
|
path_parts
|
Remaining relation segments to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[type[Model]]
|
list[type[Model]]: Models found at the end of the path. Empty when |
list[type[Model]]
|
any segment is missing. |
Source code in saffier/core/db/models/row.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 | |
__run_query
async
classmethod
¶
__run_query(model=None, extra=None, queryset=None)
Execute a relation-loading queryset with optional extra filters.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
Model whose default manager should be
used when
TYPE:
|
extra
|
Additional filter keyword arguments derived from the source row.
TYPE:
|
queryset
|
Explicit queryset to execute.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[type[Model]] | Any
|
list[type[Model]] | Any: Query result produced by the provided |
list[type[Model]] | Any
|
queryset or the model's default manager. |
Source code in saffier/core/db/models/row.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 | |
model_json_schema
classmethod
¶
model_json_schema(
*,
schema_generator=None,
mode=None,
phase=None,
include_callable_defaults=None,
**kwargs,
)
Generate the admin/marshalling JSON schema for this model.
| PARAMETER | DESCRIPTION |
|---|---|
schema_generator
|
Optional schema generator carrying callable-default policy information.
TYPE:
|
mode
|
Requested schema mode, typically validation or serialization.
TYPE:
|
phase
|
Explicit marshalling phase. When omitted, it is derived from
TYPE:
|
include_callable_defaults
|
Whether callable defaults should be preserved in the schema output.
TYPE:
|
**kwargs
|
Accepted for compatibility with Pydantic-style callers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: JSON schema generated from the model's admin |
dict[str, Any]
|
marshall class. |
Source code in saffier/core/db/models/model.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
__getattribute__
¶
__getattribute__(name)
Source code in saffier/core/db/models/model.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
model_dump
¶
model_dump(
include=None,
exclude=None,
exclude_none=False,
_seen=None,
)
Serialize declared model fields into a dictionary.
The serializer walks Saffier field declarations rather than raw
__dict__ state. That keeps virtual relation managers out of the
output, respects exclude=True, supports nested include/exclude rules,
and avoids infinite recursion by falling back to primary keys for
already-seen related objects.
| PARAMETER | DESCRIPTION |
|---|---|
include
|
Optional whitelist of fields or nested include rules.
TYPE:
|
exclude
|
Optional blacklist of fields or nested exclude rules.
TYPE:
|
exclude_none
|
Whether
TYPE:
|
_seen
|
Internal recursion guard used for nested model serialization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Serialized model payload. |
Source code in saffier/core/db/models/model.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
model_dump_json
¶
model_dump_json(
include=None, exclude=None, exclude_none=False
)
Serialize the dumped model payload into JSON.
| PARAMETER | DESCRIPTION |
|---|---|
include
|
Optional include rules forwarded to
TYPE:
|
exclude
|
Optional exclude rules forwarded to
TYPE:
|
exclude_none
|
Whether
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
JSON representation of the dumped model payload.
TYPE:
|
Source code in saffier/core/db/models/model.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
execute_pre_save_hooks
async
¶
execute_pre_save_hooks(
field_values, original_values=None, *, is_update
)
Run field-level pre-save callbacks and merge their generated values.
| PARAMETER | DESCRIPTION |
|---|---|
field_values
|
Current field payload about to be persisted.
TYPE:
|
original_values
|
Previously loaded field values for update flows.
TYPE:
|
is_update
|
Whether the hooks are executing for an update.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
dict[str, Any]: Additional column values generated by field hooks. |
Source code in saffier/core/db/models/model.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
_should_force_insert
¶
_should_force_insert()
Source code in saffier/core/db/models/model.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
_apply_persisted_db_values
¶
_apply_persisted_db_values(db_kwargs)
Source code in saffier/core/db/models/model.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
update
async
¶
update(**kwargs)
Validate, persist, and reapply an in-place update to this row.
The update path normalizes virtual field input, executes pre-save hooks, validates only the fields being changed, writes the update statement, and reapplies database-side values back onto the current instance.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Logical field values to update.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The current model instance.
TYPE:
|
Source code in saffier/core/db/models/model.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
_delete_forward_references
async
¶
_delete_forward_references(ignore_fields)
Source code in saffier/core/db/models/model.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | |
_delete_reverse_relations
async
¶
_delete_reverse_relations(ignore_fields)
Source code in saffier/core/db/models/model.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
raw_delete
async
¶
raw_delete(
*,
skip_post_delete_hooks=False,
remove_referenced_call=False,
)
Delete the row directly and perform configured relation cleanup.
Unlike delete(), this method performs the low-level delete operation
and relation cleanup directly. It is used by queryset deletion flows and
recursive cleanup helpers where signal behavior may already be managed by
the caller.
| PARAMETER | DESCRIPTION |
|---|---|
skip_post_delete_hooks
|
Accepted for backward compatibility.
TYPE:
|
remove_referenced_call
|
Internal flag used to avoid recursive cleanup loops and to decide whether delete signals should be emitted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of database rows deleted for this instance.
TYPE:
|
Source code in saffier/core/db/models/model.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
delete
async
¶
delete(skip_post_delete_hooks=False)
Delete the row and emit the standard pre/post delete signals.
| PARAMETER | DESCRIPTION |
|---|---|
skip_post_delete_hooks
|
Backward-compatible argument passed through
to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of deleted rows.
TYPE:
|
Source code in saffier/core/db/models/model.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
load
async
¶
load(only_needed=False)
Reload this instance from the database using its identifying fields.
| PARAMETER | DESCRIPTION |
|---|---|
only_needed
|
When
TYPE:
|
Source code in saffier/core/db/models/model.py
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
_save
async
¶
_save(**kwargs)
Insert a new row and reapply generated database values to the instance.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Database-ready insert payload keyed by column name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Model
|
The current persisted instance.
TYPE:
|
Source code in saffier/core/db/models/model.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
save
async
¶
save(
force_save=None,
values=None,
force_insert=None,
**kwargs,
)
Create or update the row, then persist staged relations and references.
The save flow decides between insert and update automatically unless the caller forces insertion. It validates the outgoing payload, runs field hooks, emits signals, refreshes server-generated defaults when needed, and finally persists staged model references and reverse relation writes.
| PARAMETER | DESCRIPTION |
|---|---|
force_save
|
Backward-compatible alias for forcing an insert.
TYPE:
|
values
|
Optional subset payload for partial updates.
TYPE:
|
force_insert
|
When
TYPE:
|
**kwargs
|
Additional compatibility kwargs reserved for future use.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
type[Model] | Any
|
type[Model] | Any: The current model instance. |
Source code in saffier/core/db/models/model.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
real_save
async
¶
real_save(
force_insert=False,
values=None,
force_save=None,
**kwargs,
)
Backward-compatible wrapper around save().
Older Saffier APIs used force_save; newer code uses force_insert.
This method preserves both spellings while delegating to save().
| RETURNS | DESCRIPTION |
|---|---|
type[Model] | Any
|
type[Model] | Any: Value returned by |
Source code in saffier/core/db/models/model.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
__getattr__
¶
__getattr__(name)
Resolve deferred attributes on demand.
The fallback handles computed fields, virtual relations, and unloaded
database-backed fields. Accessing an unloaded DB field triggers a
synchronous load() call through run_sync() unless the attribute was
explicitly marked as a no-load trigger.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Attribute being resolved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Resolved attribute value.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AttributeError
|
If the attribute cannot be resolved. |
Source code in saffier/core/db/models/model.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
__setattr__
¶
__setattr__(key, value)
Source code in saffier/core/db/models/model.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | |