summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/clsregistry.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-07-03 16:25:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-07-03 22:33:48 -0400
commit148711cb8515a19b6177dc07655cc6e652de0553 (patch)
treeb75505c907d25395d77f45b94919b9a17e9432cf /lib/sqlalchemy/orm/clsregistry.py
parent4b3f204d07d53ae09b59ce8f33b534f26a605cd4 (diff)
downloadsqlalchemy-148711cb8515a19b6177dc07655cc6e652de0553.tar.gz
runtime annotation fixes for relationship
* derive uselist=False when fwd ref passed to relationship This case needs to work whether or not the class name is a forward ref. we dont allow the colleciton to be a forward ref so this will work. * fix issues with MappedCollection When using string annotations or __future__.annotations, we need to do more parsing in order to get the target collection properly Change-Id: I9e5a1358b62d060a8815826f98190801a9cc0b68
Diffstat (limited to 'lib/sqlalchemy/orm/clsregistry.py')
-rw-r--r--lib/sqlalchemy/orm/clsregistry.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/clsregistry.py b/lib/sqlalchemy/orm/clsregistry.py
index b3fcd29ea..dd79eb1d0 100644
--- a/lib/sqlalchemy/orm/clsregistry.py
+++ b/lib/sqlalchemy/orm/clsregistry.py
@@ -463,6 +463,7 @@ class _class_resolver:
generic_match = re.match(r"(.+)\[(.+)\]", name)
if generic_match:
+ clsarg = generic_match.group(2).strip("'")
raise exc.InvalidRequestError(
f"When initializing mapper {self.prop.parent}, "
f'expression "relationship({self.arg!r})" seems to be '
@@ -470,7 +471,7 @@ class _class_resolver:
"please state the generic argument "
"using an annotation, e.g. "
f'"{self.prop.key}: Mapped[{generic_match.group(1)}'
- f'[{generic_match.group(2)}]] = relationship()"'
+ f"['{clsarg}']] = relationship()\""
) from err
else:
raise exc.InvalidRequestError(