MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _instance_processor

Function _instance_processor

lib/sqlalchemy/orm/loading.py:812–1254  ·  view source on GitHub ↗

Produce a mapper level row processor callable which processes rows into mapped instances.

(
    query_entity,
    mapper,
    context,
    result,
    path,
    adapter,
    only_load_props=None,
    refresh_state=None,
    polymorphic_discriminator=None,
    _polymorphic_from=None,
)

Source from the content-addressed store, hash-verified

810
811
812def _instance_processor(
813 query_entity,
814 mapper,
815 context,
816 result,
817 path,
818 adapter,
819 only_load_props=None,
820 refresh_state=None,
821 polymorphic_discriminator=None,
822 _polymorphic_from=None,
823):
824 """Produce a mapper level row processor callable
825 which processes rows into mapped instances."""
826
827 # note that this method, most of which exists in a closure
828 # called _instance(), resists being broken out, as
829 # attempts to do so tend to add significant function
830 # call overhead. _instance() is the most
831 # performance-critical section in the whole ORM.
832
833 identity_class = mapper._identity_class
834 compile_state = context.compile_state
835
836 # look for "row getter" functions that have been assigned along
837 # with the compile state that were cached from a previous load.
838 # these are operator.itemgetter() objects that each will extract a
839 # particular column from each row.
840
841 getter_key = ("getters", mapper)
842 getters = path.get(compile_state.attributes, getter_key, None)
843
844 if getters is None:
845 # no getters, so go through a list of attributes we are loading for,
846 # and the ones that are column based will have already put information
847 # for us in another collection "memoized_setups", which represents the
848 # output of the LoaderStrategy.setup_query() method. We can just as
849 # easily call LoaderStrategy.create_row_processor for each, but by
850 # getting it all at once from setup_query we save another method call
851 # per attribute.
852 props = mapper._prop_set
853 if only_load_props is not None:
854 props = props.intersection(
855 mapper._props[k] for k in only_load_props
856 )
857
858 quick_populators = path.get(
859 context.attributes, "memoized_setups", EMPTY_DICT
860 )
861
862 todo = []
863 cached_populators = {
864 "new": [],
865 "quick": [],
866 "deferred": [],
867 "expire": [],
868 "existing": [],
869 "eager": [],

Callers 1

Calls 15

_load_subclass_via_inFunction · 0.85
_tuple_getterMethod · 0.80
_should_selectin_loadMethod · 0.80
callable_for_pathMethod · 0.80
for_contextMethod · 0.80
getMethod · 0.45
intersectionMethod · 0.45
appendMethod · 0.45
_getterMethod · 0.45
create_row_processorMethod · 0.45

Tested by

no test coverage detected