sqlalchemyseed.attribute¶
attribute module containing helper functions for instrumented attribute.
Module Contents¶
- sqlalchemyseed.attribute.attr_is_column(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute)¶
Check if instrumented attribute property is a ColumnProperty
- sqlalchemyseed.attribute.attr_is_relationship(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute)¶
Check if instrumented attribute property is a RelationshipProperty
- sqlalchemyseed.attribute.check_scalar_cardinality(instance, attr_name, value, strict=False)¶
Guard against binding a list to a scalar relationship (gap #4).
A scalar relationship (
uselist=False) given a list keeps only the last element via repeated assignment — silent data loss. Whenvalueis a list of more than one item, this raises ifstrictelse warns. A single-element list is left alone (assigning one element is correct).This guard only inspects the child
valueitself: it does not detect the equivalent last-wins case expressed as a nesteddatalist (e.g.{"!company": {"data": [{...}, {...}]}}), which remains out of scope for gap #4.
- sqlalchemyseed.attribute.foreign_key_column(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute)¶
Returns the table name of the first foreignkey.
- sqlalchemyseed.attribute.instrumented_attribute(class_or_instance, key: str)¶
Returns instrumented attribute from the class or instance.
- sqlalchemyseed.attribute.referenced_class(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute)¶
Returns class that the attribute is referenced to.
- sqlalchemyseed.attribute.set_instance_attribute(instance, key, value)¶
Set attribute value of instance