Hello, I have this base model:
class AnyModel(DeclarativeBase):
__abstract__ = True
id = Column(st.Integer, primary_key=True)
def __repr__(self):
return '<{} id={}>'.format(self.__class__.__name__, self.id)
repr() seems to be printing the incorrect value for my IDs. For example,
[<Player 3>, <Player 1>, <Player 2>, <Player 1>]
[<Player 3>, <Player 1>, <Player 3>, <Player 4>]
etc...
The output is seemingly random.
Even though I have hundreds of objects in the DB, it always prints out a
number that is less than than the number of objects created per commit, and
there are duplicates and missing numbers when I query:
[<Participant id=2>, <Participant id=1>, <Participant id=3>, <Participant
id=2>, <Participant id=3>, <Participant id=5>, <Participant id=8>,
<Participant id=3>, <Participant id=8>, <Participant id=3>]
if I define the __repr__ on the child class it gives the correct output.
even though calling the super() method gives a different result:
def __repr__(self):
print('in child class dt is correct:', self.id)
print('but in base class it is', super().__repr__())
return '<{} id={}>'.format(self.__class__.__name__, self.id)
But if I rename the method __repr2__ this same issue does not occur :?
If I dump the sqlite database, the data all looks fine and consistent. IDs
are numbered sequentially 1-100 with no duplicates or gaps.
Any ideas? I tried to create a MWE but for some reason this problem only
happens in my full-scale app.
Thank you!
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/065d40f8-a146-4766-9ae2-08d406a44b9fn%40googlegroups.com.