perseas / Pyrseas

Provides utilities for Postgres database schema versioning.
https://perseas.github.io/
BSD 3-Clause "New" or "Revised" License
395 stars 67 forks source link

Pyreases doesn't like tables names public* #109

Closed reedstrm closed 10 years ago

reedstrm commented 10 years ago
Pyrseas$ git describe --tags
v0.7.1-47-g800158e

Pyrseas$ dbtoyaml test
Traceback (most recent call last):
  File "/opt/dev/bin/dbtoyaml", line 9, in <module>
    load_entry_point('Pyrseas==0.7.1', 'console_scripts', 'dbtoyaml')()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/dbtoyaml.py", line 49, in main
    dbmap = db.to_map()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 268, in to_map
    self.from_catalog()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 178, in from_catalog
    self._link_refs(self.db)
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 138, in _link_refs
    db.triggers)
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/dbobject/table.py", line 822, in link_refs
    table.owner_column = self[(sch, table.owner_table)]. \
KeyError: (u'public', 'tions')

Pyrseas$ pg_dump -s test | grep -A 4 CREATE\ TABLE
CREATE TABLE publications (
    id integer NOT NULL,
    doc text
);

Something's eating my publications table's name

jmafc commented 10 years ago

That table by itself doesn't appear to cause a problem, at least when I test against a previously empty PG 9.1 database.

What I find weird is that the last line in the traceback is reported as being line 822, but I see that line at https://github.com/perseas/Pyrseas/blob/master/pyrseas/dbobject/table.py#L819. Did you perhaps edit the file?

reedstrm commented 10 years ago

This is a 9.3 empty db. That is weird - the one I see in front me me after doing a reinstall says 819:

git diff
(dev)reedstrm@desert:/opt/dev/Pyrseas$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean
$ git remote -v
origin  https://github.com/perseas/Pyrseas.git (fetch)
origin  https://github.com/perseas/Pyrseas.git (push)
Pyrseas$ dbtoyaml test
Traceback (most recent call last):
  File "/opt/dev/bin/dbtoyaml", line 9, in <module>
    load_entry_point('Pyrseas==0.7.1', 'console_scripts', 'dbtoyaml')()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/dbtoyaml.py", line 49, in main
    dbmap = db.to_map()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 268, in to_map
    self.from_catalog()
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 178, in from_catalog
    self._link_refs(self.db)
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/database.py", line 138, in _link_refs
    db.triggers)
  File "/opt/dev/local/lib/python2.7/site-packages/Pyrseas-0.7.1-py2.7.egg/pyrseas/dbobject/table.py", line 819, in link_refs
    table.owner_column = self[(sch, table.owner_table)]. \
KeyError: (u'public', 'tions')
reedstrm commented 10 years ago

ok. testing w/ another new db, but using template0 does not fail, so I've got something installed in template1 causing this.

reedstrm commented 10 years ago

Ah 'cause my example lied, I cut it from a pg_dump. The critical bit is having a serial column:

create table publications (id serial, doc text);

even against template0 is good enough to trigger it.

jmafc commented 10 years ago

OK, reproduced. Will check what's wrong later.

reedstrm commented 10 years ago

thanks. Makes sense, that bit of code is linking up sequences owned by the table.

reedstrm commented 10 years ago

Last bit of debug - it's specific to tables that match public.public* with a serial column. A private.private* works, as does other.public*

reedstrm commented 10 years ago

Here's the code at fault: https://github.com/perseas/Pyrseas/blob/master/pyrseas/dbobject/table.py#L70-L75