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

Queryset.query not pickled correctly when saving PickledObjectField since Django 3.0 #48

Closed
flokain opened this issue Feb 19, 2020 · 3 comments

Comments

@flokain
Copy link

flokain commented Feb 19, 2020

trying to pickle a Query object.
it seems like the default values is not being serialized:

DB is postgres 10.1
django 3.0.3
python 3.7.4

eligible_team_query = PickledObjectField(default=Team.objects.all().query)

  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.SyntaxError: subquery must return only one column
LINE 1: ...query", "eligible_team_query") VALUES ('u17', '', (SELECT "p...

Originally posted by @flokain in #47 (comment)

@charettes
Copy link
Collaborator

charettes commented Feb 19, 2020

I'm afraid there's very little we'll be able to do as we want to keep allowing the usage of expressions in Field.default. In other words special casing expressions in PickledObjectField.get_default would prevent stuff like default=F('other_pickled_field'). Django 3.0 just happened to make django.db.models.sql.Query an expression which is what causing your crash here.

I assume the following works just fine?

from picklefield.fields import dbsafe_encode 

def default_eligible_team_query(self):
    return dbsafe_encode(Team.objects.all().query)

eligible_team_query = PickledObjectField(default=default_eligible_team_query)

@flokain
Copy link
Author

flokain commented Feb 20, 2020

yes this works. thank you!

@charettes charettes changed the title Queryset.query not pickled correctly when saving PickledObjectField Queryset.query not pickled correctly when saving PickledObjectField since Django 3.0 Feb 20, 2020
@charettes
Copy link
Collaborator

Alright I'll close the issue then as there's little django-picklefield can do about passing ORM internal objects to the ORM.

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