Skip to content
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

KeyError on delete #321

lukashambsch opened this issue Dec 12, 2017 · 5 comments

KeyError on delete #321

lukashambsch opened this issue Dec 12, 2017 · 5 comments


Copy link

@lukashambsch lukashambsch commented Dec 12, 2017

When trying to delete an item from the database, I am receiving a KeyError. This is part of the stack trace:

File "<string>", line 2, in delete
File "/home/ec2-user/.env/src/pony/pony/utils/", line 81, in cut_traceback
  return func(*args, **kwargs)
File "/home/ec2-user/.env/src/pony/pony/orm/", line 4539, in delete
File "/home/ec2-user/.env/src/pony/pony/orm/", line 4506, in _delete_
  obj2 = cache_index.pop(vals)
KeyError: (Order[100330699], 'AD-UNI-SMPGRP-08')

It seems the KeyError is sending me values that are part of the composite_key. Why would this be a key error on a delete?

@kozlovsky kozlovsky self-assigned this Dec 13, 2017
@kozlovsky kozlovsky added the bug label Dec 13, 2017
Copy link

@lukashambsch lukashambsch commented Dec 14, 2017

This is causing an issue in our production system. Is there a workaround?

I've tried using a delete statement using execute, but that causes an error later in the code when trying to create another object with the same composite key as the deleted object.

Copy link

@kozlovsky kozlovsky commented Dec 14, 2017

At this moment I don't fully understand what may be the reason for the error and how to reproduce it. Can you show model definitions or send them privately? Also, you write that you delete object and immediately create a new objects with the same key. Are you sure this is necessary? Maybe it is better to just update the previous object?

Copy link

@lukashambsch lukashambsch commented Dec 14, 2017

Removing the delete entirely was my first thought too. It's some old code that doesn't have any testing in place, so I'm hesitant to just remove it entirely. I'm afraid of corrupting the data. I can share the model definition privately. How would you like me to send them?

Copy link

@kozlovsky kozlovsky commented Dec 14, 2017

You can send them to my email

@kozlovsky kozlovsky closed this in 23aec34 Dec 20, 2017
Copy link

@kozlovsky kozlovsky commented Dec 20, 2017

Thanks for the reporting, we were able to reproduce and fix the problem

@kozlovsky kozlovsky added this to the 0.7.4 milestone Dec 20, 2017
kozlovsky added a commit that referenced this issue Jul 23, 2018
# Major features

* Hybrid methods and properties added:
* Allow to base queries on another queries: `select(x.a for x in prev_query if x.b)`
* Added support of Python 3.7
* Added support of PyPy
* `group_concat()` aggregate function added
* pony.flask subpackage added for integration with Flask

# Other features

* `distinct` option added to aggregate functions
* Support of explicit casting to `float` and `bool` in queries

# Improvements

* Apply @cut_traceback decorator only when pony.MODE is 'INTERACTIVE'

# Bugfixes

* In SQLite3 `LIKE` is case sensitive now
* #249: Fix incorrect mixin used for Timedelta
* #251: correct dealing with qualified table names
* #301: Fix aggregation over JSON Column
* #306: Support of frozenset constants added
* #308: Fixed an error when assigning JSON attribute value to the same attribute: obj.json_attr = obj.json_attr
* #313: Fix missed retry on exception raised during db_session.__exit__
* #314: Fix AttributeError: 'NoneType' object has no attribute 'seeds'
* #315: Fix attribute lifting for JSON attributes
* #321: Fix KeyError on obj.delete()
* #325: duplicating percentage sign in raw SQL queries without parameters
* #331: Overriding __len__ in entity fails
* #336: entity declaration serialization
* #357: reconnect after PostgreSQL server closed the connection unexpectedly
* Fix Python implementation of between() function and rename arguments: between(a, x, y) -> between(x, a, b)
* Fix retry handling: in PostgreSQL and Oracle an error can be raised during commit
* Fix optimistic update checks for composite foreign keys
* Don't raise OptimisticCheckError if db_session is not optimistic
* Handling incorrect datetime values in MySQL
* Improved ImportError exception messages when MySQLdb, pymysql, psycopg2 or psycopg2cffi driver was not found
* desc() function fixed to allow reverse its effect by calling desc(desc(x))
* __contains__ method should check if objects belong to the same db_session
* Fix pony.MODE detection; mod_wsgi detection according to official doc
* A lot of inner fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants