MetaData.sorted_tables is inconsistant

45 views
Skip to first unread message

Ofir Herzas

unread,
Jun 14, 2015, 9:06:50 AM6/14/15
to sqlal...@googlegroups.com
It seems that MetaData.sorted_tables returns a different result each time.
While the results seem to be always correct, it is an odd behavior.

I would expect sorted_tables to return the same results every time

import sqlalchemy as sa
engine
= sa.create_engine("<db_url>", echo=False)

meta
= sa.MetaData(bind=engine, reflect=True)
a
= [t.name for t in meta.sorted_tables]

meta
= sa.MetaData(bind=engine, reflect=True)
b
= [t.name for t in meta.sorted_tables]

a and b are not sorted the same

BTW: meta.tables is consistent ...

Mike Bayer

unread,
Jun 14, 2015, 9:46:30 AM6/14/15
to sqlal...@googlegroups.com

On 6/14/15 9:06 AM, Ofir Herzas wrote:
It seems that MetaData.sorted_tables returns a different result each time.
While the results seem to be always correct, it is an odd behavior.
A topological sort is non-deterministic.   If two elements A and B have no dependency on each other, they can be returned in either order.

However, the sorted_tables accessor was  specifically enhanced to use a deterministic sorting in 1.0, where the list of items passed to the topological algorithm is first sorted alphabetically, and an ordered set is used internally, so that it comes up with the same result each time.

So, did you try 1.0 ?





I would expect sorted_tables to return the same results every time

import sqlalchemy as sa
engine
= sa.create_engine("<db_url>", echo=False)

meta
= sa.MetaData(bind=engine, reflect=True)
a
= [t.name for t in meta.sorted_tables]

meta
= sa.MetaData(bind=engine, reflect=True)
b
= [t.name for t in meta.sorted_tables]

a and b are not sorted the same

BTW: meta.tables is consistent ...
--
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+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Ofir Herzas

unread,
Jun 14, 2015, 11:08:41 AM6/14/15
to sqlal...@googlegroups.com

Nope, I still use 0.9.7 J

It's not a big deal, just seemed odd, but thanks, I will look at it again once I move to 1.0 …

--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/eYZvKK12qTo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages