Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert
On 8/22/20 12:09 PM, Vitaly Kruglikov wrote: > Hi Richard. I wish it was that simple, but it's not. Here is an > example of how using a builtin name breaks: > > ``` > In [3]: unique = object() > ...: class TestId: > ...: id = 'something else' > ...: unique_id = id(unique) > ...: > ...: > Which would be the expected problem with hiding global names, but you could do unique = object() real_id = id class TestId: id = 'something else' unique_id = real_id(unique) The other option might be to put the column definitions into the table_args for the table (but that loses the column object) -- Richard Damon -- 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/9b0e37af-68b9-1569-64cd-4c0e1a185d4a%40Damon-Family.org.
Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert
Hi Richard. I wish it was that simple, but it's not. Here is an example of how using a builtin name breaks: ``` In [3]: unique = object() ...: class TestId: ...: id = 'something else' ...: unique_id = id(unique) ...: ...: --- TypeError Traceback (most recent call last) in 1 unique = object() > 2 class TestId: 3 id = 'something else' 4 unique_id = id(unique) 5 in TestId() 2 class TestId: 3 id = 'something else' > 4 unique_id = id(unique) 5 6 TypeError: 'str' object is not callable ``` On Saturday, August 22, 2020 at 8:09:19 AM UTC-7 Richard Damon wrote: > On 8/22/20 10:46 AM, Vitaly Kruglikov wrote: > > I suspect this has something to do with the combination of the > > explicit definition of the `id_` column and reflection, but don't know > > how to fix. I really need to keep the explicit `id_` descriptor and > > shouldn't rename it to `id` because that's a reserved python word. > > > I would note that 'id' is NOT a reserved word (aka key-word) in Python, > but the name of a built-in. As such id(xx) [which uses the built in] and > obj.id [which can reference the id member of that object] are not > incompatible. Don't use it as a variable name, as that would cause > issues, but in an explicit scope like a class it works. > > -- > Richard Damon > > -- 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/9fb87feb-203f-43a5-a449-77fe815262b3n%40googlegroups.com.
Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert
On 8/22/20 10:46 AM, Vitaly Kruglikov wrote: > I suspect this has something to do with the combination of the > explicit definition of the `id_` column and reflection, but don't know > how to fix. I really need to keep the explicit `id_` descriptor and > shouldn't rename it to `id` because that's a reserved python word. > I would note that 'id' is NOT a reserved word (aka key-word) in Python, but the name of a built-in. As such id(xx) [which uses the built in] and obj.id [which can reference the id member of that object] are not incompatible. Don't use it as a variable name, as that would cause issues, but in an explicit scope like a class it works. -- Richard Damon -- 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/be9c0312-0fff-c543-1434-4550c00ed7a1%40Damon-Family.org.