Comments (11)
Please provide a test case to reproduce.
from django-picklefield.
First think I found this morning is that v0.3.1 values_list('picklefield')
would return undecoded strings. V0.3.2 decodes them. This breaks any code that tries to dbsafe_decode
a values_list.
Running some more tests.
from django-picklefield.
The problem seems to be that in Django 1.8.4 , the values_list values are nice and decoded.
In Django 1.7.10 , the values_list values still return encoded .Which was the old behavior.
from django-picklefield.
testmodel = TestModel.objects.first()
testmodel.picklefield = 'hello'
TestModel.objects.filter(pk=testmodel.pk).values_list('picklefield', flat=True)[0]==testmodel.picklefield
In the current version , this is only true for Django 1.8.4 and not for Django 1.7.10
The fix for this used to be to dbsafe_decode
the value, but since it's now already decoded with 1.8.4, dbsafe_decode
raises an exception.
from django-picklefield.
As of Django 1.8+ you should expect all fields to be automatically decoded when using values(_list)?()
as documented in the release notes.
You weren't getting any failures when using django-picklefield==0.3.1
because it was using the deprecated SubfieldBase
API that was removed in 9cabb40.
Since this Django change is definitely an improvement and is here to stay I'll close this ticket.
from django-picklefield.
Do you have a suggestion how I run my code on both versions of Django without having to resort to checking for Django versions?
from django-picklefield.
I'm afraid this will really hard to achieve without relying on Django version checking. Can you point me to some code?
from django-picklefield.
I agree with you that this is a real improvement and I'm happy someone has taken it upon themselves to keep django-picklefield up to date.
@staticmethod
def get_result_group(group_id, failures=False):
# values + decode is 10 times faster than just list comprehension
if failures:
values = Task.objects.filter(group=group_id).values_list('result', flat=True)
else:
values = Task.objects.filter(group=group_id).exclude(success=False).values_list('result', flat=True)
return [dbsafe_decode(t) for t in values]
https://github.com/Koed00/django-q/blob/master/django_q/models.py
After the 0.3.2 update I removed the dbsafe_decode() iteration and that tested just fine. Unfortunately my projects tries to be 1.7 compatible too, so those tests then failed on Travis.
I've been thinking about refactoring a version of dbsafe_encode with a try clause in it, but that feels counterproductive. There is no real way of determining if a string is base64 encoded either.
from django-picklefield.
I'd would suggest you create a compat
module with the following code and import it wherever you need to do some conditional decoding.
from picklefield import PickledObjectField, dbsafe_decode
if hasattr(PickledObjectField, 'from_db_value'):
def decode_results(values):
return values
else:
def decode_results(values):
return [dbsafe_decode(v) for v in values]
from django-picklefield.
Perfect, thanks a million.
from django-picklefield.
You could then replace your method by:
from .compat import decode_results
...
def get_result_group(group_id, failures=False):
# values + decode is 10 times faster than just list comprehension
if failures:
values = Task.objects.filter(group=group_id).values_list('result', flat=True)
else:
values = Task.objects.filter(group=group_id).exclude(success=False).values_list('result', flat=True)
return decode_results(values)
And simply remove the decode_results
compatibly shim when dropping support for Django 1.7.
from django-picklefield.
Related Issues (20)
- Field.get_db_prep_lookup() method has been removed in Django 1.10
- The test_settings.py file is not included in the tarball HOT 1
- Deepcopy could be configurable HOT 1
- problem about filter HOT 1
- problem subclassing and overriding from_db_value HOT 2
- Django 2.0: from_db_value() context parameter facing deprecation HOT 1
- mutable default value causes issues HOT 3
- 1.1.0 not available on PyPi? HOT 1
- ModuleNotFoundError: No module named 'django' on installing dependencies HOT 2
- Setup.py depends indirectly on Django HOT 3
- Make admin editable widget a TextArea HOT 2
- Default field value not working in Django 3 HOT 5
- Queryset.query not pickled correctly when saving PickledObjectField since Django 3.0 HOT 3
- RemovedInDjango40Warning: force_text() is deprecated in favor of force_str() HOT 1
- Cannot use PickleField to save a QuerySet query HOT 1
- Package cannot be built from source without installing Django first HOT 11
- Django 3.2 test failure due to DEFAULT_AUTO_FIELD HOT 1
- RuntimeWarning: Pickled model instance's Django version HOT 1
- [Feature Request] Support Django 4.2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-picklefield.