Giter Club home page Giter Club logo

Comments (2)

graingert avatar graingert commented on July 22, 2024

Ah yes master is broken, see the tests on Travis. #92 (comment)

from sqlalchemy-redshift.

MarSoft avatar MarSoft commented on July 22, 2024

Similar problem with latest version from pypi - anyway this example still doesn't work:

EXAMPLE 1 BEFORE:  None Example #1
Traceback (most recent call last):
  File "test.py", line 50, in <module>
    print("EXAMPLE 1 AFTER: ", example_1.id, example_1.name)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 237, in __get__
    return self.impl.get(instance_state(instance), dict_)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 579, in get
    value = state._load_expired(state, passive)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 592, in _load_expired
    self.manager.deferred_scalar_loader(self, toload)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 703, in load_scalar_attributes
    raise orm_exc.ObjectDeletedError(state)
sqlalchemy.orm.exc.ObjectDeletedError: Instance '<IdentityExample at 0x7f0da95b68d0>' has been deleted, or its row is otherwise not present.

If I set engine.echo = True, I get the following:

2017-06-01 09:08:29,163 INFO sqlalchemy.engine.base.Engine select version()
2017-06-01 09:08:29,163 INFO sqlalchemy.engine.base.Engine {}
2017-06-01 09:08:29,618 INFO sqlalchemy.engine.base.Engine select current_schema()
2017-06-01 09:08:29,618 INFO sqlalchemy.engine.base.Engine {}
2017-06-01 09:08:30,073 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2017-06-01 09:08:30,073 INFO sqlalchemy.engine.base.Engine {}
2017-06-01 09:08:30,301 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2017-06-01 09:08:30,301 INFO sqlalchemy.engine.base.Engine {}
2017-06-01 09:08:30,982 INFO sqlalchemy.engine.base.Engine select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2017-06-01 09:08:30,983 INFO sqlalchemy.engine.base.Engine {'name': u'identity_example'}
2017-06-01 09:08:31,445 INFO sqlalchemy.engine.base.Engine
DROP TABLE identity_example
2017-06-01 09:08:31,445 INFO sqlalchemy.engine.base.Engine {}
2017-06-01 09:08:31,920 INFO sqlalchemy.engine.base.Engine COMMIT
2017-06-01 09:08:32,152 INFO sqlalchemy.engine.base.Engine select relname from pg_class c join pg_namespace n on n.oid=c.relnamespace where pg_catalog.pg_table_is_visible(c.oid) and relname=%(name)s
2017-06-01 09:08:32,153 INFO sqlalchemy.engine.base.Engine {'name': u'identity_example'}
1 before None john
2017-06-01 09:08:32,850 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2017-06-01 09:08:32,856 INFO sqlalchemy.engine.base.Engine INSERT INTO identity_example (name) VALUES (%(name)s)
2017-06-01 09:08:32,857 INFO sqlalchemy.engine.base.Engine {'name': 'Example #1'}
2017-06-01 09:08:33,331 INFO sqlalchemy.engine.base.Engine COMMIT
2017-06-01 09:08:33,695 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2017-06-01 09:08:33,696 INFO sqlalchemy.engine.base.Engine SELECT identity_example.id AS identity_example_id, identity_example.name AS identity_example_name
FROM identity_example
WHERE identity_example.id = %(param_1)s
2017-06-01 09:08:33,696 INFO sqlalchemy.engine.base.Engine {'param_1': 0}
Traceback (most recent call last):
  File "test.py", line 50, in <module>
    print("EXAMPLE 1 AFTER: ", example_1.id, example_1.name)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 237, in __get__
    return self.impl.get(instance_state(instance), dict_)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 579, in get
    value = state._load_expired(state, passive)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/state.py", line 592, in _load_expired
    self.manager.deferred_scalar_loader(self, toload)
  File "/tmp/env/lib/python2.7/site-packages/sqlalchemy/orm/loading.py", line 703, in load_scalar_attributes
    raise orm_exc.ObjectDeletedError(state)
sqlalchemy.orm.exc.ObjectDeletedError: Instance '<IdentityExample at 0x7f0da95b68d0>' has been deleted, or its row is otherwise not present.

For me it looks like redshift-sqlalchemy uses ResultProxy.lastrowid, but for some reason (I could not figure it out yet) that value for RedShift is always 0, regardless of which ID was created or was not created.

The only way I know to obtain an ID of newly inserted record is to SELECT max(id) FROM table within the same transaction, which is probably not consistent but should hopefully work at least partially.

from sqlalchemy-redshift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.