On Thu, Feb 16, 2023, at 7:16 AM, Lele Gaifax wrote: > Hi all, > > while testing one of my tools[1] against SA2 I found that one test is > failing, and couldn't figure out a proper workaround. > > TL;DR > > Why is the sqlalchemy.ext.hybrid.Comparator.property explicitly > raising a NotImplementedError?
the .property attribute in the base PropComparator refers to an ORM instrumented attribute, which in the case of a custom Comparator does not exist. This was None previously, but for typing purposes, now raises NotImplementedError since it should not be accessed. > Traceback (most recent call last): > File ".../src/metapensiero/sqlalchemy/dbloady/load.py", line 223, in > workhorse > load(fname, session, dry_run, delete, save_new_instances, > File ".../src/metapensiero/sqlalchemy/dbloady/load.py", line 124, in > load > for e in entity(session, idmap, adaptor): > File ".../src/metapensiero/sqlalchemy/dbloady/entity.py", line 85, in > __call__ > yield instance(session, self.delete, self.loadonly) > File ".../src/metapensiero/sqlalchemy/dbloady/entity.py", line 189, in > __call__ > attr_prop = getattr(model, f).property > File "...lib/python3.10/site-packages/sqlalchemy/orm/attributes.py", > line 645, in property > return self.comparator.property > File "...lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", > line 1127, in __get__ > return self.fget(obj) > File "...lib/python3.10/site-packages/sqlalchemy/ext/hybrid.py", line > 1191, in property > raise NotImplementedError() > NotImplementedError > > As you can see here[5], my code tries to obtain the "property" attribute > of the comparator to determine whether it should assign a scalar value > or an instance to the target. > > In SA 2, the ext.hybrid.Comparator explicitly[6] defines the > "property" property as "not defined" (sorry for the pun), and I could > not figure out the rationale. > > While I keep digging and trying, maybe you can shed some light, or > hinting about a different approach? dont use getattr(), use methods like inspect(cls).attrs, inspect(cls).relationships and inspect(cls).all_orm_descriptors to get a view for what ORM things are associated with the class and which are relationships. that all works in 1.4 also. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/a42282fc-ab8f-4f48-8b7a-e3f4b354d168%40app.fastmail.com.