[Sqlalchemy-tickets] Issue #3826: Session commit changes the order of a relationship elements (zzze
Brought to you by:
zzzeek
From: metalstorm <iss...@bi...> - 2016-10-15 18:08:24
|
New issue 3826: Session commit changes the order of a relationship elements https://bitbucket.org/zzzeek/sqlalchemy/issues/3826/session-commit-changes-the-order-of-a metalstorm: If you have a model that contains a basic relationship like so: ``` #!python from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, Table, DateTime from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Thing(Base) parts = relationship('Part', backref='thing') class Part(Base): name = Column(String, primary_key=True, default='') ``` And then you do: ``` #!python thing = Thing() part1 = Part(name="Part1") part2 = Part(name="Part2") # Note we do part2 then part1 thing.parts.append(part2) thing.parts.append(part1) print thing.parts # [Part2, Part1] session.commit() print thing.parts # [Part1, Part2] ``` It seems like the session orders the result based on primary key (by default), which I guess is expected. But if the session already contains the instances, then should it change the order? |