-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
prefetch causes fields to be added in dirty_fields #2091
Comments
@coleifer Please check it. I got this behavior again on Peewee 3.13.3, Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32. |
The regression test is passing fine for me. If you add a failing test, I will look into this again. |
from peewee import CharField, ForeignKeyField, Model, SqliteDatabase
database = SqliteDatabase(":memory:")
class A(Model):
class Meta:
database = database
only_save_dirty = True
some_str = CharField()
class B(Model):
class Meta:
database = database
only_save_dirty = True
another_str = CharField()
a_instance = ForeignKeyField(model=A)
if __name__ == "__main__":
database.create_tables(models=[A, B])
a = A.create(some_str='s1')
B.create(another_str='s2', a_instance=a)
b1 = B.select().where(B.another_str == 's2').execute()[0]
print(f"Without `prefetch`, dirty fields: {b1.dirty_fields}")
b2 = B.select().where(B.another_str == 's2').prefetch(A)[0]
print(f"With `prefetch`, dirty fields: {b2.dirty_fields}") |
OP DELIVERS. Thank you! |
Hey - I think I see the problem. There's absolutely no reason to use query = B.select(B, A).join(A).where(B.another_str == 's2') |
prefetch
causes fields related to prefetched models to be added indirty_fields
.Could you say why this is so? Is it not possible to make another implementation?
Thanks so much for the answer and excellent ORM.
The text was updated successfully, but these errors were encountered: