hi - that's a bug! The .params() method is kind of forgotten. https://github.com/sqlalchemy/sqlalchemy/issues/6124 is added, however this is not a regression since this is using new functionality on select(). I think I have a fairly straightforward fix for this however it won't be in SQLAlchemy 1.4.3, which needs to go out very soon.
For now I would advise sending the params directly to the session.execute() method. On Tue, Mar 23, 2021, at 9:35 PM, Dane K Barney wrote: > I am using SQLAlchemy 1.4.2 and have been encountering this strange error > message which I've managed to boil down to this minimal example: > > import sqlalchemy as sa > from sqlalchemy.orm import declarative_base, relationship > > Base = declarative_base() > > class Parent(Base): > __tablename__ = "parent" > id = sa.Column(sa.Integer, primary_key=True) > > > class Child(Base): > __tablename__ = "child" > id = sa.Column(sa.Integer, primary_key=True) > parent_id = sa.Column(sa.Integer, sa.ForeignKey("parent.id")) > parent = relationship("Parent") > > > statement = sa.select([Child.id]).join(Child.parent).where(Parent.id == > sa.bindparam("id")) > > statement = statement.params(id=10) > > > The call to statement.params(...) is throwing the following stacktrace. Can > anyone tell me what I'm doing wrong? > > Traceback (most recent call last): > File "test_sqlalchemy_error.py", line 20, in <module> > statement = statement.params(id=10) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line > 346, in params > return self._replace_params(False, optionaldict, kwargs) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line > 363, in _replace_params > return cloned_traverse(self, {}, {"bindparam": visit_bindparam}) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line > 742, in cloned_traverse > obj = clone(obj, deferred_copy_internals=deferred_copy_internals) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line > 735, in clone > newelem._copy_internals(clone=clone, **kw) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/selectable.py", line > 5208, in _copy_internals > clone=clone, omit_attrs=("_from_obj",), **kw > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/traversals.py", line > 718, in _copy_internals > result = meth(attrname, self, obj, **kw) > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/traversals.py", line > 777, in visit_setup_join_tuple > for (target, onclause, from_, flags) in element > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/traversals.py", line > 777, in <genexpr> > for (target, onclause, from_, flags) in element > File ".venv/lib/python3.7/site-packages/sqlalchemy/sql/visitors.py", line > 736, in clone > meth = visitors.get(newelem.__visit_name__, None) > File ".venv/lib/python3.7/site-packages/sqlalchemy/orm/attributes.py", line > 308, in __getattr__ > replace_context=err, > File ".venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line > 198, in raise_ > raise exception > AttributeError: Neither 'QueryableAttribute' object nor 'Comparator' object > associated with Child.parent has an attribute '__visit_name__' > > > > -- > 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/e1696eff-495e-4db9-a88a-cc385bbc8690n%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/e1696eff-495e-4db9-a88a-cc385bbc8690n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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/c79f4dc5-19fe-45db-a32e-822023466e54%40www.fastmail.com.