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

Unique attributes are lazy loaded #451

Closed
gabriel-ilie opened this issue Jun 26, 2019 · 1 comment
Closed

Unique attributes are lazy loaded #451

gabriel-ilie opened this issue Jun 26, 2019 · 1 comment

Comments

@gabriel-ilie
Copy link

python2.7
pony orm 0.7.10


from pony.orm import *
db = Database()

class A(db.Entity):
name=Required(str, unique=True)
b = Set('B')

class B(db.Entity):
x = Required(str)
a = Required('A')

db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)

with db_session:
a = A(name='name')
b = B(a=a, x='x')

with db_session:
b = B.get(x='x')
#b.a.load()
b.a.name = 'sss'

====================>
Traceback (most recent call last):
File "/mnt/hgfs/share/pony_orm_unique_keys_not_loaded.py", line 22, in
b.a.name = 'sss'
File "/usr/local/lib/python2.7/dist-packages/pony/orm/core.py", line 2357, in set
for undo_func in reversed(undo_funcs): undo_func()
File "/usr/local/lib/python2.7/dist-packages/pony/orm/core.py", line 2323, in undo_func
if old_val is NOT_LOADED: obj.vals.pop(attr)
KeyError: A.name

If I uncomment << b.a.load() >> everything works as expected;
If I use << b.a.set(name='sss') >> everything works as expected.
If I make name attribute not unique everything works as expected.
If I specify lazy=False for name it is still lazy loaded.

@ChiliConSql
Copy link

I am having the same issue.
python 3.7
pony 0.7.10

any suggestions?

kozlovsky added a commit that referenced this issue Nov 23, 2020
# Features

* Add Python 3.9 support
* Allow to use kwargs in select: Entity.select(**kwargs) and obj.collection.select(**kwargs), a feature that was announced but actually missed from 0.7.7
* Add support for volatile collection attributes that don't throw "Phantom object appeared/disappeared" exceptions

# Bugfixes

* Fix negative timedelta conversions
* Pony should reconnect to PostgreSQL when receiving 57P01 error (AdminShutdown)
* Allow mixing compatible types (like int and float) in coalesce() arguments
* Support of subqueries in coalesce() arguments
* Fix using aggregated subqueries in ORDER BY section
* Fix queries with expressions like `(x, y) in ((a, b), (c, d))`
* #451: KeyError for seeds with unique attributes in SessionCache.update_simple_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants