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