hey there -

it seems pretty likely that the source of objects you are using, which would be 
the "query" you refer towards, or some process afterwards by which these 
objects are assembled into the list you are printing,  contains the same object 
instance multiple times, hence you see the same IDs indicated multiple times.

The reality of your situation might be much different than this, however the 
information provided is extremely scant which prevents me from having any 
better answer.



On Sun, Dec 6, 2020, at 9:26 AM, RexE wrote:
> 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
>  
> <https://groups.google.com/d/msgid/sqlalchemy/065d40f8-a146-4766-9ae2-08d406a44b9fn%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/7d132c34-1e78-47ad-b3bb-93b3e25cd528%40www.fastmail.com.

Reply via email to