Re: [sqlalchemy] Re: SQL expression object expected, got object of type instead
This seems to be correct, the issue does not occur if I run the exact same code locally. Lambda must be doing something, somehow, that is causing this. Any advice on how to fix the problem? On Friday, February 14, 2020 at 9:10:49 AM UTC-5, Mike Bayer wrote: > > this looks like something up with the environment or the interpreter. > The error message says it got an object whose type() returns > "BinaryExpression". that is exactly the type it is looking for; this > class should be a subclass of sqlalchemy.sql.visitors.Visitable. However > for this error to occur, that is suddenly not the case, or the Visitable / > BinaryExpression symbol has been modified at runtime, something like > that.It's not clear if this could be some artifact of AWS Lambda, or > the way the application is doing imports, or something like that. > > the approach here would be to make a test program that produces the error > under AWS Lambda, then run it in a local Python environment and see if the > results are the same or different. > > On Fri, Feb 14, 2020, at 5:16 AM, Simon King wrote: > > Can you show the real code that runs the query? I'm wondering whether > the thing that you are comparing against my_table.c.name is not > actually a simple string. > > Simon > > On Wed, Feb 12, 2020 at 11:01 PM Mark Wilkins > wrote: > > > > Some additional code incase its relevent: > > > > # Get DB connection > > engine = setup_env_db_engine(debug=True) > > connection = engine.connect() > > > > # Configure SQLalchemy > > meta = MetaData(bind=engine) > > meta.reflect() > > > > my_table = meta.tables.get('my_table') > > > > > > -- > > 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 sqlal...@googlegroups.com . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/839938dd-ed33-4f55-a836-185ec0689f2f%40googlegroups.com > . > > -- > 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 sqlal...@googlegroups.com . > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfyHn5OKiAm8k9QX3R3Gm4xAoZRy7%3Dg33L%3DdO%3DvSDumZg%40mail.gmail.com > . > > > -- 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/5ca02432-e957-412d-91a4-4f4c9dd67f0c%40googlegroups.com.
Re: [sqlalchemy] Re: SQL expression object expected, got object of type instead
This is the actual code, with table names swapped out. I've confirmed that my_table.c.name is infact a column, and the comparison operation generates a BinaryExpression object as it is supposed to. The issue is that where() throws an exception indicating it doesn't accept BinaryExpression objects, even though it is supposed to. On Friday, February 14, 2020 at 5:16:40 AM UTC-5, Simon King wrote: > > Can you show the real code that runs the query? I'm wondering whether > the thing that you are comparing against my_table.c.name is not > actually a simple string. > > Simon > > On Wed, Feb 12, 2020 at 11:01 PM Mark Wilkins > wrote: > > > > Some additional code incase its relevent: > > > > # Get DB connection > > engine = setup_env_db_engine(debug=True) > > connection = engine.connect() > > > > # Configure SQLalchemy > > meta = MetaData(bind=engine) > > meta.reflect() > > > > my_table = meta.tables.get('my_table') > > > > > > -- > > 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 sqlal...@googlegroups.com . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/839938dd-ed33-4f55-a836-185ec0689f2f%40googlegroups.com. > > > -- 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/add65511-ec23-4414-a56c-910a2cc3c4ec%40googlegroups.com.
Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?
There's no point in really having the visible_id on the A table, other than for inheritance. The point of it being on B (and C, D, E, F, etc.) is that they have unique sequences populating those "Visible IDs", so I have can have a B-1 and a C-1 and a D-1. In other words I have my parent table A with id, visible_id, type 1, 1, "B" 2, 2, "C" 3, 3, "D" 4, 4, "E" B id, visible_id --- 1, 1 C id, visible_id 2, 1 etc. The alternative (I suppose) would be somehow configuring A.visible_id to use a different sequence for every child class table, although a.) i dont know if you can do that and b.) it's less desirable to have duplicate values in that column. On Friday, February 14, 2020 at 12:55:47 PM UTC-5, Simon King wrote: > > On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino > wrote: > > > > I have a polymorphic class structure like this, with a lot of classes > extending the parent class. > > In reality I'm using a Mixin that declares the visible_id column and > it's defined with @declared_attr.cascading, but for simplicity: > > > > > > > > class A(Base): > > __tablename__ = 'a' > > id = Column(Integer, primary_key=True) > >visible_id = Column(Integer) > > > > class B(A): > > __tablename__ = 'b' > > id = Column(Integer, ForeignKey("A.id"), primary_key=True) > > visible_id = Column(Integer) > > > > > > What I need for my application is to query A.visible_id and return the > CHILD values for B.visible_id (and all the others). > > > > The inheritance works fine, i.e. if i query all As in the database, my > response is a list of [B] objects, but unless I directly query B the > visible_id from A takes precedence and I cannot query A.visible_id if I > remove it from A. > > > > Can anyone tell me how to configure this? > > > > Out of interest, what is the point of having a visible_id column in > the B table? I'm having difficulty imagining what it would mean to > have an instance of B (which due to inheritance is also an instance of > A) which has different values in A.visible_id and B.visible_id. > > Simon > -- 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/546e5a4a-7ab5-4350-888a-6f8d54fb822c%40googlegroups.com.
Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?
There's no point in really having the visible_id on the A table, other than for inheritance. The point of it being on B (and C, D, E, F, etc.) is that they have unique sequences populating those "Visible IDs", so I have can have a B-1 and a C-1 and a D-1. In other words I have my parent table A with id, visible_id, type 1, 1, "B" 1, 2, "C" 1, 3, "D" 1, 4, "E" B id, visible_id --- 1, 1 C id, visible_id 2, 1 etc. The alternative (I suppose) would be somehow configuring A.visible_id to use a different sequence for every child class table, although a.) i dont know if you can do that and b.) it's less desirable to have duplicate values in that column. On Friday, February 14, 2020 at 12:55:47 PM UTC-5, Simon King wrote: > > On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino > wrote: > > > > I have a polymorphic class structure like this, with a lot of classes > extending the parent class. > > In reality I'm using a Mixin that declares the visible_id column and > it's defined with @declared_attr.cascading, but for simplicity: > > > > > > > > class A(Base): > > __tablename__ = 'a' > > id = Column(Integer, primary_key=True) > >visible_id = Column(Integer) > > > > class B(A): > > __tablename__ = 'b' > > id = Column(Integer, ForeignKey("A.id"), primary_key=True) > > visible_id = Column(Integer) > > > > > > What I need for my application is to query A.visible_id and return the > CHILD values for B.visible_id (and all the others). > > > > The inheritance works fine, i.e. if i query all As in the database, my > response is a list of [B] objects, but unless I directly query B the > visible_id from A takes precedence and I cannot query A.visible_id if I > remove it from A. > > > > Can anyone tell me how to configure this? > > > > Out of interest, what is the point of having a visible_id column in > the B table? I'm having difficulty imagining what it would mean to > have an instance of B (which due to inheritance is also an instance of > A) which has different values in A.visible_id and B.visible_id. > > Simon > -- 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/6dcc5932-64f4-4aaa-b766-a747d285e132%40googlegroups.com.
Re: [sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?
On Fri, Feb 14, 2020 at 5:35 PM Mark Aquino wrote: > > I have a polymorphic class structure like this, with a lot of classes > extending the parent class. > In reality I'm using a Mixin that declares the visible_id column and it's > defined with @declared_attr.cascading, but for simplicity: > > > > class A(Base): > __tablename__ = 'a' > id = Column(Integer, primary_key=True) >visible_id = Column(Integer) > > class B(A): > __tablename__ = 'b' > id = Column(Integer, ForeignKey("A.id"), primary_key=True) > visible_id = Column(Integer) > > > What I need for my application is to query A.visible_id and return the CHILD > values for B.visible_id (and all the others). > > The inheritance works fine, i.e. if i query all As in the database, my > response is a list of [B] objects, but unless I directly query B the > visible_id from A takes precedence and I cannot query A.visible_id if I > remove it from A. > > Can anyone tell me how to configure this? > Out of interest, what is the point of having a visible_id column in the B table? I'm having difficulty imagining what it would mean to have an instance of B (which due to inheritance is also an instance of A) which has different values in A.visible_id and B.visible_id. Simon -- 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/CAFHwexf305mqE_NRqxF2Pv1H9j9ngt6wVHpLmWaVRHi2Ot4o2g%40mail.gmail.com.
[sqlalchemy] how to "explicitly" combine columns, for example get the child class value from a query on parent class from same named column?
I have a polymorphic class structure like this, with a lot of classes extending the parent class. In reality I'm using a Mixin that declares the visible_id column and it's defined with @declared_attr.cascading, but for simplicity: class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) visible_id = Column(Integer) class B(A): __tablename__ = 'b' id = Column(Integer, ForeignKey("A.id"), primary_key=True) visible_id = Column(Integer) What I need for my application is to query A.visible_id and return the CHILD values for B.visible_id (and all the others). The inheritance works fine, i.e. if i query all As in the database, my response is a list of [B] objects, but unless I directly query B the visible_id from A takes precedence and I cannot query A.visible_id if I remove it from A. Can anyone tell me how to configure this? Thanks! -- 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/9a248c3e-ec1a-4e18-b663-3a03bab027e5%40googlegroups.com.
Re: [sqlalchemy] Re: SQL expression object expected, got object of type instead
this looks like something up with the environment or the interpreter. The error message says it got an object whose type() returns "BinaryExpression". that is exactly the type it is looking for; this class should be a subclass of sqlalchemy.sql.visitors.Visitable. However for this error to occur, that is suddenly not the case, or the Visitable / BinaryExpression symbol has been modified at runtime, something like that. It's not clear if this could be some artifact of AWS Lambda, or the way the application is doing imports, or something like that. the approach here would be to make a test program that produces the error under AWS Lambda, then run it in a local Python environment and see if the results are the same or different. On Fri, Feb 14, 2020, at 5:16 AM, Simon King wrote: > Can you show the real code that runs the query? I'm wondering whether > the thing that you are comparing against my_table.c.name is not > actually a simple string. > > Simon > > On Wed, Feb 12, 2020 at 11:01 PM Mark Wilkins > wrote: > > > > Some additional code incase its relevent: > > > > # Get DB connection > > engine = setup_env_db_engine(debug=True) > > connection = engine.connect() > > > > # Configure SQLalchemy > > meta = MetaData(bind=engine) > > meta.reflect() > > > > my_table = meta.tables.get('my_table') > > > > > > -- > > 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/839938dd-ed33-4f55-a836-185ec0689f2f%40googlegroups.com. > > -- > 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/CAFHwexfyHn5OKiAm8k9QX3R3Gm4xAoZRy7%3Dg33L%3DdO%3DvSDumZg%40mail.gmail.com. > -- 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/0b0007e2-8e97-4ef3-a7e7-e08338619307%40www.fastmail.com.
Re: [sqlalchemy] Re: SQL expression object expected, got object of type instead
Can you show the real code that runs the query? I'm wondering whether the thing that you are comparing against my_table.c.name is not actually a simple string. Simon On Wed, Feb 12, 2020 at 11:01 PM Mark Wilkins wrote: > > Some additional code incase its relevent: > > # Get DB connection > engine = setup_env_db_engine(debug=True) > connection = engine.connect() > > # Configure SQLalchemy > meta = MetaData(bind=engine) > meta.reflect() > > my_table = meta.tables.get('my_table') > > > -- > 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/839938dd-ed33-4f55-a836-185ec0689f2f%40googlegroups.com. -- 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/CAFHwexfyHn5OKiAm8k9QX3R3Gm4xAoZRy7%3Dg33L%3DdO%3DvSDumZg%40mail.gmail.com.