sqlalchemyseed.attribute ======================== .. py:module:: sqlalchemyseed.attribute .. autoapi-nested-parse:: attribute module containing helper functions for instrumented attribute. Module Contents --------------- .. py:function:: attr_is_column(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute) Check if instrumented attribute property is a ColumnProperty .. py:function:: attr_is_relationship(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute) Check if instrumented attribute property is a RelationshipProperty .. py:function:: 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. When ``value`` is a list of more than one item, this raises if ``strict`` else warns. A single-element list is left alone (assigning one element is correct). This guard only inspects the child ``value`` itself: it does not detect the equivalent last-wins case expressed as a nested ``data`` list (e.g. ``{"!company": {"data": [{...}, {...}]}}``), which remains out of scope for gap #4. .. py:function:: foreign_key_column(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute) Returns the table name of the first foreignkey. .. py:function:: instrumented_attribute(class_or_instance, key: str) Returns instrumented attribute from the class or instance. .. py:function:: referenced_class(instrumented_attr: sqlalchemy.orm.attributes.InstrumentedAttribute) Returns class that the attribute is referenced to. .. py:function:: set_instance_attribute(instance, key, value) Set attribute value of instance