From 54e848dfed020e0600fb0d50a80a4d94ad745747 Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Tue, 16 Feb 2021 12:35:32 -0700 Subject: Add reflection_options to automapbase.prepare() Fixes: #5942 Change-Id: If72ccca93fbe303799b1bacb7339c4c85e4251aa --- lib/sqlalchemy/ext/automap.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/ext/automap.py b/lib/sqlalchemy/ext/automap.py index 6d90214bf..3d2e3eb29 100644 --- a/lib/sqlalchemy/ext/automap.py +++ b/lib/sqlalchemy/ext/automap.py @@ -779,6 +779,7 @@ class AutomapBase(object): name_for_scalar_relationship=None, name_for_collection_relationship=None, generate_relationship=None, + reflection_options=util.EMPTY_DICT, ): """Extract mapped classes and relationships from the :class:`_schema.MetaData` and @@ -830,6 +831,13 @@ class AutomapBase(object): .. versionadded:: 1.1 + :param reflection_options: When present, this dictionary of options + will be passed to :meth:`_schema.MetaData.reflect` + to supply general reflection-specific options like ``only`` and/or + dialect-specific options like ``oracle_resolve_synonyms``. + + .. versionadded:: 1.4 + """ glbls = globals() if classname_for_table is None: @@ -854,12 +862,14 @@ class AutomapBase(object): autoload_with = engine if reflect: - cls.metadata.reflect( - autoload_with, + opts = dict( schema=schema, extend_existing=True, autoload_replace=False, ) + if reflection_options: + opts.update(reflection_options) + cls.metadata.reflect(autoload_with, **opts) with _CONFIGURE_MUTEX: table_to_map_config = dict( -- cgit v1.2.1