MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _reconcile

Method _reconcile

lib/sqlalchemy/orm/strategy_options.py:1821–1875  ·  view source on GitHub ↗

define behavior for when two Load objects are to be put into the context.attributes under the same key. :param replacement: ``_LoadElement`` that seeks to replace the existing one :param existing: ``_LoadElement`` that is already present.

(
        replacement: _LoadElement, existing: _LoadElement
    )

Source from the content-addressed store, hash-verified

1819
1820 @staticmethod
1821 def _reconcile(
1822 replacement: _LoadElement, existing: _LoadElement
1823 ) -> _LoadElement:
1824 """define behavior for when two Load objects are to be put into
1825 the context.attributes under the same key.
1826
1827 :param replacement: ``_LoadElement`` that seeks to replace the
1828 existing one
1829
1830 :param existing: ``_LoadElement`` that is already present.
1831
1832 """
1833 # mapper inheritance loading requires fine-grained "block other
1834 # options" / "allow these options to be overridden" behaviors
1835 # see test_poly_loading.py
1836
1837 if replacement._reconcile_to_other:
1838 return existing
1839 elif replacement._reconcile_to_other is False:
1840 return replacement
1841 elif existing._reconcile_to_other:
1842 return replacement
1843 elif existing._reconcile_to_other is False:
1844 return existing
1845
1846 if existing is replacement:
1847 return replacement
1848 elif (
1849 existing.strategy == replacement.strategy
1850 and existing.local_opts == replacement.local_opts
1851 ):
1852 return replacement
1853 elif replacement.is_opts_only:
1854 existing = existing._clone()
1855 existing.local_opts = existing.local_opts.union(
1856 replacement.local_opts
1857 )
1858 existing._extra_criteria += replacement._extra_criteria
1859 return existing
1860 elif existing.is_opts_only:
1861 replacement = replacement._clone()
1862 replacement.local_opts = replacement.local_opts.union(
1863 existing.local_opts
1864 )
1865 replacement._extra_criteria += existing._extra_criteria
1866 return replacement
1867 elif replacement.path.is_token:
1868 # use 'last one wins' logic for wildcard options. this is also
1869 # kind of inconsistent vs. options that are specific paths which
1870 # will raise as below
1871 return replacement
1872
1873 raise sa_exc.InvalidRequestError(
1874 f"Loader strategies for {replacement.path} conflict"
1875 )
1876
1877
1878class _AttributeStrategyLoad(_LoadElement):

Callers 1

process_compile_stateMethod · 0.80

Calls 2

_cloneMethod · 0.45
unionMethod · 0.45

Tested by

no test coverage detected