Re: [sqlalchemy] SQL expression object expected, got object of type instead
Never mind. This problem is solved by join operations. Thanks for your attention. On Friday, January 28, 2022 at 4:16:05 AM UTC+13 Simon King wrote: > I'm sorry, I still don't understand - what do you expect > query(Genome.attributes) to do? Can you give an example? > > Thanks, > > Simon > > On Wed, Jan 26, 2022 at 11:30 PM Simon wrote: > > > > Sorry for that the question is not clear. The question is how can we > query a database's property. > > > > Given the above example, if query(Genome.id) or > query(Genome.created_date), it works fine. But if I query the property, > query(Genome.attributes): it raises the exception. > > > > Thanks. > > Simon > > > > On Wednesday, January 26, 2022 at 12:53:52 AM UTC+13 Simon King wrote: > >> > >> Can you show the part of *your* code that is triggering the error, and > >> explain what you are trying to do? Plain python properties aren't > >> normally very useful when accessed via a class. "Genome.attributes" > >> returns a property object, not the return value from the function, and > >> I don't understand what you are trying to do with it. > >> > >> Thanks, > >> > >> Simon > >> > >> On Mon, Jan 24, 2022 at 2:03 AM Simon wrote: > >> > > >> > Hi there, > >> > > >> > I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression > object expected, got object of type instead' > >> > > >> > My SQLAlchemy version is 1.3.22. I have a database like > >> > > >> > Class Genome: > >> > id = Column(Integer, primary_key=True) > >> > created_date = Column(Datetime, nullable=False) > >> > > >> > @property > >> > def attributes(self): > >> > return "something" > >> > > >> > > >> > If using the query, it reports an error through the elements.py in > the sqlAlchemy > >> > > >> > def _literal_as(element, text_fallback): > >> > if isinstance(element, Visitable): > >> > return element > >> > elif hasattr(element, "__clause_element__"): > >> > return element.__clause_element__() > >> > elif isinstance(element, util.string_types): > >> > return text_fallback(element) > >> > elif isinstance(element, (util.NoneType, bool)): > >> > return _const_expr(element) > >> > else: > >> > raise exc.ArgumentError( > >> > "SQL expression object expected, got object of type %r " > >> > "instead" % type(element) > >> > ) > >> > > >> > This exception is not raised if I directly query genome's column name > such as created_date or id. > >> > > >> > I am wondering 1) could the column name and property be used > interchangeably in some way? Or say how could to query a table's property > in the way of querying a table's column? 2) what are some significant > differences between table's column name and property? > >> > > >> > 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+...@googlegroups.com. > >> > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/7f03c9bb-9324-4e3e-8aea-cd0d46f9021bn%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+...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/2fbf2d83-6865-4b9b-8db6-cb5f60e0eaffn%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/3255fd36-2eb8-4b4a-a4c0-00e289450d74n%40googlegroups.com.
Re: [sqlalchemy] SQL expression object expected, got object of type instead
I'm sorry, I still don't understand - what do you expect query(Genome.attributes) to do? Can you give an example? Thanks, Simon On Wed, Jan 26, 2022 at 11:30 PM Simon wrote: > > Sorry for that the question is not clear. The question is how can we query a > database's property. > > Given the above example, if query(Genome.id) or query(Genome.created_date), > it works fine. But if I query the property, query(Genome.attributes): it > raises the exception. > > Thanks. > Simon > > On Wednesday, January 26, 2022 at 12:53:52 AM UTC+13 Simon King wrote: >> >> Can you show the part of *your* code that is triggering the error, and >> explain what you are trying to do? Plain python properties aren't >> normally very useful when accessed via a class. "Genome.attributes" >> returns a property object, not the return value from the function, and >> I don't understand what you are trying to do with it. >> >> Thanks, >> >> Simon >> >> On Mon, Jan 24, 2022 at 2:03 AM Simon wrote: >> > >> > Hi there, >> > >> > I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object >> > expected, got object of type instead' >> > >> > My SQLAlchemy version is 1.3.22. I have a database like >> > >> > Class Genome: >> > id = Column(Integer, primary_key=True) >> > created_date = Column(Datetime, nullable=False) >> > >> > @property >> > def attributes(self): >> > return "something" >> > >> > >> > If using the query, it reports an error through the elements.py in the >> > sqlAlchemy >> > >> > def _literal_as(element, text_fallback): >> > if isinstance(element, Visitable): >> > return element >> > elif hasattr(element, "__clause_element__"): >> > return element.__clause_element__() >> > elif isinstance(element, util.string_types): >> > return text_fallback(element) >> > elif isinstance(element, (util.NoneType, bool)): >> > return _const_expr(element) >> > else: >> > raise exc.ArgumentError( >> > "SQL expression object expected, got object of type %r " >> > "instead" % type(element) >> > ) >> > >> > This exception is not raised if I directly query genome's column name such >> > as created_date or id. >> > >> > I am wondering 1) could the column name and property be used >> > interchangeably in some way? Or say how could to query a table's property >> > in the way of querying a table's column? 2) what are some significant >> > differences between table's column name and property? >> > >> > 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+...@googlegroups.com. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msgid/sqlalchemy/7f03c9bb-9324-4e3e-8aea-cd0d46f9021bn%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/2fbf2d83-6865-4b9b-8db6-cb5f60e0eaffn%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/CAFHwexeT_AcTbbJ561Rx%3D3jDdAFxshTMHrJ7jFSzKiGMZC6Y9Q%40mail.gmail.com.
Re: [sqlalchemy] SQL expression object expected, got object of type instead
Can you show the part of *your* code that is triggering the error, and explain what you are trying to do? Plain python properties aren't normally very useful when accessed via a class. "Genome.attributes" returns a property object, not the return value from the function, and I don't understand what you are trying to do with it. Thanks, Simon On Mon, Jan 24, 2022 at 2:03 AM Simon wrote: > > Hi there, > > I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object > expected, got object of type instead' > > My SQLAlchemy version is 1.3.22. I have a database like > > Class Genome: > id = Column(Integer, primary_key=True) > created_date = Column(Datetime, nullable=False) > > @property > def attributes(self): > return "something" > > > If using the query, it reports an error through the elements.py in the > sqlAlchemy > > def _literal_as(element, text_fallback): > if isinstance(element, Visitable): > return element > elif hasattr(element, "__clause_element__"): > return element.__clause_element__() > elif isinstance(element, util.string_types): > return text_fallback(element) > elif isinstance(element, (util.NoneType, bool)): > return _const_expr(element) > else: > raise exc.ArgumentError( > "SQL expression object expected, got object of type %r " > "instead" % type(element) > ) > > This exception is not raised if I directly query genome's column name such as > created_date or id. > > I am wondering 1) could the column name and property be used interchangeably > in some way? Or say how could to query a table's property in the way of > querying a table's column? 2) what are some significant differences between > table's column name and property? > > 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/7f03c9bb-9324-4e3e-8aea-cd0d46f9021bn%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/CAFHwexfKm%2Bx8AMg8de%2BXx5CQ6AM62%2BWfth3v%2BgGB8LzE9SbK%3Dw%40mail.gmail.com.
[sqlalchemy] SQL expression object expected, got object of type instead
Hi there, I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type instead' My SQLAlchemy version is 1.3.22. I have a database like Class Genome: id = Column(Integer, primary_key=True) created_date = Column(Datetime, nullable=False) @property def attributes(self): return "something" If using the query, it reports an error through the elements.py in the sqlAlchemy def _literal_as(element, text_fallback): if isinstance(element, Visitable): return element elif hasattr(element, "__clause_element__"): return element.__clause_element__() elif isinstance(element, util.string_types): return text_fallback(element) elif isinstance(element, (util.NoneType, bool)): return _const_expr(element) else: raise exc.ArgumentError( "SQL expression object expected, got object of type %r " "instead" % type(element) ) This exception is not raised if I directly query genome's column name such as created_date or id. I am wondering 1) could the column name and property be used interchangeably in some way? Or say how could to query a table's property in the way of querying a table's column? 2) what are some significant differences between table's column name and property? 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/7f03c9bb-9324-4e3e-8aea-cd0d46f9021bn%40googlegroups.com.