WHOIGit / domdb

DOM mass spec database prototype
MIT License
1 stars 3 forks source link

db_demo remove does not work #5

Closed redbluewater closed 10 years ago

redbluewater commented 10 years ago

capture3

joefutrelle commented 10 years ago

Looks like other parts of the CLI are out of sync with the same ORM changes:

ubuntu@dashboard-v28:~/domdb$ python db_demo.py 
18215 metabolites in database
Hi Krista
(Cmd) count tps4
Traceback (most recent call last):
  File "db_demo.py", line 122, in <module>
    shell.cmdloop('Hi Krista')
  File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
    return func(arg)
  File "db_demo.py", line 68, in do_count
    n = mtab_count(session, exp)
  File "db_demo.py", line 43, in mtab_count
    q = q.filter(Mtab.exp_name == exp)
AttributeError: type object 'Mtab' has no attribute 'exp_name'
joefutrelle commented 10 years ago

Aha, doesn't work to write

session.query(Mtab).filter(Mtab.exp.name==exp)

Instead, in SQLAlchemy, one has to write

session.query(Mtab).filter(Mtab.exp.has(name=exp))

That fixed the "count" query but I'm getting an unfamiliar error when I try to fix the "remove" command the same way:

ubuntu@dashboard-v28:~/domdb$ python db_demo.py 
18215 metabolites in database
Hi Krista
(Cmd) remove tps4
Removing all tps4 data ...
Traceback (most recent call last):
  File "db_demo.py", line 122, in <module>
    shell.cmdloop('Hi Krista')
  File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
    return func(arg)
  File "db_demo.py", line 107, in do_remove
    session.query(Mtab).filter(Mtab.exp.has(name=exp)).delete()
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 2603, in delete
    delete_op.exec_()
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 815, in exec_
    self._do_pre_synchronize()
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/persistence.py", line 866, in _do_pre_synchronize
    "Could not evaluate current criteria in Python. "
sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.
joefutrelle commented 10 years ago

That's because the query, which used to be a simple one, is now a join, and so SQLAlchemy needs a synchronization strategy parameter. Works like a charm.

http://stackoverflow.com/questions/7892618/sqlalchemy-delete-subquery

Chasing down more out of date references before I close this out. More than just the remove command is affected.

joefutrelle commented 10 years ago

Fixed, but not pushing yet until I fix a related issue, which I'll open momentarily.

redbluewater commented 10 years ago

As an aside (since we are both learning here)...I think I figured out why GitHub ignored my changes yesterday about notifications. There is clearly a delay between 'changing your notification options' and 'something actually getting changed'.

Krista

On 10/9/2014 4:45 PM, Joe Futrelle wrote:

Fixed, but not pushing yet until I fix a related issue, which I'll open momentarily.

— Reply to this email directly or view it on GitHub https://github.com/joefutrelle/domdb/issues/5#issuecomment-58574821.

Krista Longnecker Woods Hole Oceanographic Institution Marine Chemistry and Geochemistry Fye 112, MS#4 360 Woods Hole Road Woods Hole, MA 02543-1541 http://www.whoi.edu/people/klongnecker/

klongnecker@whoi.edu 508 289 2824

joefutrelle commented 10 years ago

fixed