New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Release unlocked lock' error after 'delete'. #386

Closed
ichorid opened this Issue Oct 4, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@ichorid
Copy link

ichorid commented Oct 4, 2018

This code:

from pony import orm
from pony.orm import db_session

db = orm.Database()

class TestClass1(db.Entity):
    rowid = orm.PrimaryKey(int, auto=True)
    val = orm.Optional(int, default=0)

db.bind(provider='sqlite', filename=":memory:", create_db=True)
db.generate_mapping(create_tables=True)

@db_session
def fun1():
    TestClass1.exists(val=12)
    return TestClass1()

@db_session
def fun2():
    a = TestClass1()
    a.delete()
    q = fun1()
    print q

def main():
    with db_session:
        fun2()

if __name__ == "__main__":
    main()

produces this error:

Traceback (most recent call last):
  File "./pony_bug_get.py", line 34, in <module>
    main()
  File "./pony_bug_get.py", line 30, in main
    fun2()
  File "<auto generated wrapper of fun2() function>", line 2, in fun2
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 480, in new_func
    reraise(exc_type, exc, tb)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 467, in new_func
    result = func(*args, **kwargs)
  File "./pony_bug_get.py", line 24, in fun2
    q = fun1()
  File "<auto generated wrapper of fun1() function>", line 2, in fun1
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 480, in new_func
    reraise(exc_type, exc, tb)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 468, in new_func
    commit()
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 349, in commit
    transact_reraise(CommitException, exceptions)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 319, in transact_reraise
    reraise(exc_class, new_exc, tb)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 343, in commit
    primary_cache.commit()
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 1727, in commit
    cache.database.provider.commit(cache.connection, cache)
  File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/dbproviders/sqlite.py", line 315, in commit
    provider.transaction_lock.release()
pony.orm.core.CommitException: error: release unlocked lock
@ichorid

This comment has been minimized.

Copy link
Author

ichorid commented Oct 4, 2018

FYI: if we put select with [:] before exists, the bug is not triggered.

@ichorid

This comment has been minimized.

Copy link
Author

ichorid commented Oct 4, 2018

orm.flush() has the same bug-nullifying effect.

@kozlovsky kozlovsky self-assigned this Oct 4, 2018

@kozlovsky kozlovsky added the bug label Oct 4, 2018

@kozlovsky kozlovsky added this to the 0.7.7 milestone Oct 4, 2018

@kozlovsky

This comment has been minimized.

Copy link
Member

kozlovsky commented Oct 4, 2018

Simplified code to reproduce:

from pony.orm import *

db = Database('sqlite', ':memory:')

class TestClass1(db.Entity):
    val = Required(int)

db.generate_mapping(create_tables=True)

with db_session:
    a = TestClass1(val=1)
    a.delete()
    TestClass1.exists(val=2)

@kozlovsky kozlovsky closed this in 287a05e Oct 5, 2018

@kozlovsky

This comment has been minimized.

Copy link
Member

kozlovsky commented Oct 5, 2018

Should work now

kozlovsky added a commit that referenced this issue Jan 17, 2019

PonyORM release 0.7.7 (2019-01-17)
# Major features

* Array type support for PostgreSQL and SQLite
* isinstance() support in queries
* Support of queries based on collections: select(x for x in y.items)

# Other features

* Support of Entity.select(**kwargs)
* Support of SKIP LOCKED option in 'SELECT ... FOR UPDATE'
* New function make_proxy(obj) to make cros-db_session proxy objects
* Specify ON DELETE CASCADE/SET NULL in foreign keys
* Support of LIMIT in `SELECT FROM (SELECT ...)` type of queries
* Support for negative JSON array indexes in SQLite

# Improvements

* Improved query prefetching: use fewer number of SQL queries
* Memory optimization: deduplication of values recieved from the database in the same session
* increase DBAPIProvider.max_params_count value

# Bugfixes

* #405: breaking change with cx_Oracle 7.0: DML RETURNING now returns a list
* #380: db_session should work with async functions
* #385: test fails with python3.6
* #386: release unlocked lock error in SQLite
* #390: TypeError: writable buffers are not hashable
* #398: add auto coversion of numpy numeric types
* #404: GAE local run detection
* Fix Flask compatibility: add support of LocalProxy object
* db_session(sql_debug=True) should log SQL commands also during db_session.__exit__()
* Fix duplicated table join in FROM clause
* Fix accessing global variables from hybrid methods and properties
* Fix m2m collection loading bug
* Fix composite index bug: stackoverflow.com/questions/53147694
* Fix MyEntity[obj.get_pk()] if pk is composite
* MySQL group_concat_max_len option set to max of 32bit platforms to avoid truncation
* Show all attribute options in show(Entity) call
* For nested db_session retry option should be ignored
* Fix py_json_unwrap
* Other minor fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment