Hello everybody,
Today, I have a strange problem regarding relationships.
My project contains already several relationships and until now, I never
had any problem with these. But now, when I try to add a new relationship
between two classes, the entire program suddenly crashes without displaying
any error message. It looks like an infinite loop.
I am sadly not able to reproduce the problem in a small example.
I have a lot of classes with several relationships and the informations are
sometimes redundant and not optimized. For example:
Player has a relationship with Race.
Race has a relationship with Skeleton.
Player has a relationship with Skeleton.
It means that the Skeleton is also present in Player while the Skeleton may
also be accessible via Race...
This is due to the fact that I am working from an existing project whose
save system was based on Pickle.
Let's take the following example and let's assume that it reflects my
problem and crashes.
class Player(Base):
__tablename__ = 'player'
id = Column(Integer, primary_key=True)
id_weapon = Column(Integer, ForeignKey('weapon.id'))
weapon = relationship("Weapon", back_populates="players")
id_room = Column(Integer, ForeignKey('room.id'))
room = relationship("Room", back_populates="players")
... other relationships
class Weapon(Base):
__tablename__ = 'weapon'
id = Column(Integer, primary_key=True)
players = relationship("Player", back_populates="weapon")
... other relationships
def __init__(arg1, arg2):
print("I will never be executed.")
... some code
class Room(Base):
__tablename__ = 'room'
id = Column(Integer, primary_key=True)
players = relationship("Player", back_populates="room")
... other relationships
I tried to determine which line makes the whole thing crashes and it
happens when I try to do this:
*w = Weapon(arg1, arg2)*
What is strange is that the __init__ is not executed. It crashes between
the call *Weapon(arg1, arg2)* and the __init__. The print function*
print("I will never be executed.")* will for example not be executed.
And I have just one __init__ in this class.
When I delete one of the relationships in the class Weapon, everything
works fine.
My hypothesis is that SQLAlchemy try to do something with relationships
when Weapon(arg1, arg2) is executed and for some reasons, it crashes. Like
I said, my relationships network is a bit strange and absolutly not
optimized. Is it possible that the relationships and the back_populates are
causing Infinite Loops ?
Has someone already see that ? How could I learn more about the problem and
figure out what SQLALchemy is trying to do and where it crashes ?
Thank you.
Sven
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.