Coder Social home page Coder Social logo

django-picklefield's Introduction

django-picklefield

License Latest Version Build Status Coverage Status Supported Python Versions Wheel Status

About

django-picklefield provides an implementation of a pickled object field. Such fields can contain any picklable objects.

The implementation is taken and adopted from Django snippet #1694 by Taavi Taijala, which is in turn based on Django snippet #513 by Oliver Beattie.

django-picklefield is available under the MIT license.

Usage

First of all, you need to have django-picklefield installed; for your convenience, recent versions should be available from PyPI.

To use, just define a field in your model:

>>> from picklefield.fields import PickledObjectField
... class SomeObject(models.Model):
...     args = PickledObjectField()

and assign whatever you like (as long as it's picklable) to the field:

>>> obj = SomeObject()
>>> obj.args = ['fancy', {'objects': 'inside'}]
>>> obj.save()

Notes

If you need to serialize an object with a PickledObjectField for transmission to the browser, you may need to subclass the field and override the value_to_string() method. Currently pickle fields are serialized as base64-encoded pickles, which allows reliable deserialization, but such a format is not convenient for parsing in the browser. By overriding value_to_string() you can choose a more convenient serialization format.

Fields now accept the boolean key word argument copy, which defaults to True. The copy is necessary for lookups to work correctly. If you don't care about performing lookups on the picklefield, you can set copy=False to save on some memory usage. This an be especially beneficial for very large object trees.

Running tests

The full test suite can be run with Tox:

>>> pip install tox
>>> tox

Original notes

Here are the notes by taavi223, the original author:

Incredibly useful for storing just about anything in the database (provided it is Pickle-able, of course) when there isn't a 'proper' field for the job.

PickledObjectField is database-agnostic, and should work with any database backend you can throw at it. You can pass in any Python object and it will automagically be converted behind the scenes. You never have to manually pickle or unpickle anything. Also works fine when querying; supports exact, in, and isnull lookups. It should be noted, however, that calling QuerySet.values() will only return the encoded data, not the original Python object.

This PickledObjectField has a few improvements over the one in snippet #513.

This one solves the DjangoUnicodeDecodeError problem when saving an object containing non-ASCII data by base64 encoding the pickled output stream. This ensures that all stored data is ASCII, eliminating the problem.

PickledObjectField will now optionally use zlib to compress (and uncompress) pickled objects on the fly. This can be set per-field using the keyword argument "compress=True". For most items this is probably not worth the small performance penalty, but for Models with larger objects, it can be a real space saver.

You can also now specify the pickle protocol per-field, using the protocol keyword argument. The default of 2 should always work, unless you are trying to access the data from outside of the Django ORM.

Worked around a rare issue when using the cPickle and performing lookups of complex data types. In short, cPickle would sometimes output different streams for the same object depending on how it was referenced. This of course could cause lookups for complex objects to fail, even when a matching object exists. See the docstrings and tests for more information.

You can now use the isnull lookup and have it function as expected. A consequence of this is that by default, PickledObjectField has null=True set (you can of course pass null=False if you want to change that). If null=False is set (the default for fields), then you wouldn't be able to store a Python None value, since None values aren't pickled or encoded (this in turn is what makes the isnull lookup possible).

You can now pass in an object as the default argument for the field without it being converted to a unicode string first. If you pass in a callable though, the field will still call it. It will not try to pickle and encode it.

You can manually import dbsafe_encode and dbsafe_decode from fields.py if you want to encode and decode objects yourself. This is mostly useful for decoding values returned from calling QuerySet.values(), which are still encoded strings.

Note: If you are trying to store other django models in the PickledObjectField, please see the comments for a discussion on the problems associated with doing that. The easy solution is to put django models into a list or tuple before assigning them to the PickledObjectField.

Update 9/2/09: Fixed the value_to_string method so that serialization should now work as expected. Also added deepcopy back into dbsafe_encode, fixing #4 above, since deepcopy had somehow managed to remove itself. This means that lookups should once again work as expected in all situations. Also made the field editable=False by default (which I swear I already did once before!) since it is never a good idea to have a PickledObjectField be user editable.

Changes

Changes in version 3.2.0

  • Added tested support for Django 4.1, 4.2, 5.0.
  • Added tested support for Python 3.11, 3.12.
  • Dropped support for Python 3.6 and 3.7.

Changes in version 3.1.0

  • Added tested support for Django 3.2 and 4.0.

Changes in version 3.0.1

  • None; addressed a packaging issue with 3.0.0

Changes in version 3.0.0

  • Allowed default pickle protocol to be overriden using the PICKLEFIELD_DEFAULT_PROTOCOL setting.
  • Dropped support for Python 2.
  • Added testing against Django 3.0.
  • Dropped support for Django 1.11.

Changes in version 2.1.0

  • Added official support for Django 2.2 (thanks to joehybird).
  • Dropped support for Django 2.0 and 2.1 (thanks to joehybird).
  • Dropped support for Python 3.4 (thanks to joehybidd).

Changes in version 2.0.0

  • Silenced RemovedInDjango30Warning warnings on Django 2.0+ (thanks to canarduck).
  • Restructured project directories.
  • Disallowed the usage of empty strings for PickledObjectField. That makes .save(), .create(), etc. raise IntegrityError if null is not True and no default value was specified like built-in fields do (thanks to Attila-Mihaly Balazs).
  • Added a check for mutable default values to PickledObjectField.

Changes in version 1.1.0

  • Added support for Django 2.1 and dropped support for Django < 1.11.

Changes in version 1.0.0

  • Added a new option to prevent a copy of the object before pickling: copy=True
  • Dropped support for Django 1.4
  • Dropped support for Django 1.7
  • Dropped support for Python 3.2
  • Added support for Python 3.6

Changes in version 0.3.2

  • Dropped support for Django 1.3.
  • Dropped support for Python 2.5.
  • Silenced deprecation warnings on Django 1.8+.

Changes in version 0.3.1

  • Favor the built in json module (thanks to Simon Charette).

Changes in version 0.3.0

  • Python 3 support (thanks to Rafal Stozek).

Changes in version 0.2.0

  • Allow pickling of subclasses of django.db.models.Model (thanks to Simon Charette).

Changes in version 0.1.9

  • Added connection and prepared parameters to get_db_prep_value() too (thanks to Matthew Schinckel).

Changes in version 0.1.8

  • Updated link to code repository.

Changes in version 0.1.7

  • Added connection and prepared parameters to get_db_prep_lookup() to get rid of deprecation warnings in Django 1.2.

Changes in version 0.1.6

Changes in version 0.1.5

  • Added support for South.
  • Changed default to null=False, as is common throughout Django.

Changes in version 0.1.4

  • Updated copyright statements.

Changes in version 0.1.3

  • Updated serialization tests (thanks to Michael Fladischer).

Changes in version 0.1.2

  • Added Simplified BSD licence.

Changes in version 0.1.1

  • Added test for serialization.
  • Added note about JSON serialization for browser.
  • Added support for different pickle protocol versions (thanks to Michael Fladischer).

Changes in version 0.1

  • First public release.

Feedback

There is a home page <http://github.com/gintas/django-picklefield> with instructions on how to access the code repository.

Send feedback and suggestions to [email protected] .

django-picklefield's People

Contributors

adamchainz avatar canarduck avatar carltongibson avatar cdman avatar charettes avatar felixxm avatar gintas avatar jarshwah avatar joehybird avatar kishorkunal-raj avatar rafales avatar schinckel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-picklefield's Issues

mutable default value causes issues

There seems to be issues if a mutable default value is used. I'm not sure the best way to handle this, though.

Example:

class MyModel(models.Model):
    pickle = PickledObjectField(default={})
x = MyModel()
x.pickle['a'] = 3
x.pickle  #  {'a': 3}

y = MyModel()
y.pickle   # {'a': 3}

Setup.py depends indirectly on Django

This commit causes installation from source to fail if Django is not already installed when setup.py is called. (For instance when attempting to install all project packages in one go to a clean environment like a container or virtualenv.)

Is VERSION necessary? If not then __version__ can just be a string constant which is much easier to read.

Otherwise, ugly as it may be, could I suggest the following; it depends only on packages that will be present if setuptools is installed, which is reasonably likely in a clean environment, unlike Django:

from pkg_resources import packaging

VERSION = (2, 0, 0, 'alpha', 0)
__version__ = str(packaging.version.Version('.'.join(str(p) for p in VERSION)))

Migrate this fork to a canonical repository in Github

I propose this fork to be migrated to a canonical repository in GitHub.

shrubberysoft/django-pickle "died" and it seems that the fork that is maintaining it should become a canonical repository.

This also makes it easier to find django-picklefield repository on github (I mean, the one currently being maintained).

Package cannot be built from source without installing Django first

On systems where no binary build is available, django-picklefield cannot be installed in a clean virtualenv, because it relies on Django being installed at build time

To reproduce:

$ mkvirtualenv -p python3.8 test-django-picklefield-build
$ workon test-django-picklefield-build
$ pip install --no-binary django-picklefield django-picklefield
Collecting django-picklefield
  Using cached django-picklefield-3.0.1.tar.gz (9.5 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/niklas/.virtualenvs/test-django-picklefield/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-install-7k5uva3e/django-picklefield/setup.py'"'"'; __file__='"'"'/private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-install-7k5uva3e/django-picklefield/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-pip-egg-info-m4z3m_ay
         cwd: /private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-install-7k5uva3e/django-picklefield/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-install-7k5uva3e/django-picklefield/setup.py", line 5, in <module>
        import picklefield
      File "/private/var/folders/zy/5k15xt89127ck1l3sk615l5m0000gn/T/pip-install-7k5uva3e/django-picklefield/picklefield/__init__.py", line 3, in <module>
        import django.utils.version
    ModuleNotFoundError: No module named 'django'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

The obvious fix is to maintain the version differently, e.g. niklasb@dc29798

getting AttributeError: 'NoneType' object has no attribute 'strip' when trying the sample code

When I try the example code, I'm getting an error. Can someone help? Thanks.
model:

from picklefield import PickledObjectField

class SomeObject(models.Model):
args = PickledObjectField()

manage.py shell:

from scratch.models import SomeObject
obj = SomeObject()
obj.args = ['a', {'a':3}]
obj.save()

Traceback (most recent call last):
File "", line 1, in
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/base.py", line 545, in save
force_update=force_update, update_fields=update_fields)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/base.py", line 573, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/base.py", line 654, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/base.py", line 687, in _do_insert
using=using, raw=raw)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/manager.py", line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/query.py", line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/models/sql/compiler.py", line 903, in execute_sql
cursor.execute(sql, params)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/django/db/backends/util.py", line 73, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/mysql/connector/django/base.py", line 330, in last_executed_query
return cursor.statement
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/mysql/connector/django/base.py", line 129, in getattr
return getattr(self.cursor, attr)
File "/home/jack/workspace/venv0/lib/python3.3/site-packages/mysql/connector/cursor.py", line 868, in statement
return self._executed.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

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

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)

problem about filter

I got a problem when I used OBJ.objects.filter(field__exact=my_dict)
sample:

class FieldTest(models.Model):
    gene = PickledObjectField()
def check(my_dict):
    test=FieldTest.objects.create(gene=my_dict)
    print FieldTest.objects.filter(gene__exact=my_dict)
    print FieldTest.objects.filter(gene__exact=test.gene)
    print FieldTest.objects.filter()[0].gene==my_dict

when I used dict1

{'FGA': ['25', '25'], 'D13S317': ['8', '10'], 'D6S1043': ['18', '16'], 'D2S1338': ['22', '23'], 'AMEL': ['X', 'Y'], 'D3S1358': ['16', '17'], 'CSF1PO': ['12', '12'], 'D16S539': ['10', '11']}

print as

[<FieldTest: FieldTest object>]
[<FieldTest: FieldTest object>]
True

when I used dict2

{'FGA': ['25', '25'], 'D13S317': ['8', '10'], 'D6S1043': ['18', '16'], 'D2S1338': ['22', '23'], 'AMEL': ['X', 'Y'], 'D3S1358': ['16', '17'], 'CSF1PO': ['12', '12'], 'D16S539': ['10', '11'], 'TPOX': ['8', '8'], 'D21S11': ['28', '29'], 'D7S820': ['10', '11'], 'vWA': ['14', '18'], 'PentaE': ['10', '17'], 'TH01': ['7', '9'], 'D12S391': ['18', '23'], 'D8S1179': ['13', '15'], 'PentaD': ['9', '13'], 'D18S51': ['14', '19'], 'D5S818': ['19', '19'], 'D19S433': ['12', '12']}

print as

[]
[]
True

problem :dict1 and dict2 has same structure,why can not filter when used dict2

Django 2.0: from_db_value() context parameter facing deprecation

When testing with Django 2.0, there's a warning

RemovedInDjango30Warning: Remove the context parameter from PickledObjectField.from_db_value(). Support for it will be removed in Django 3.0.

The Django ticket tracking the removal is 28730.
The commit adding this deprecation warning is django/django@487362f.

Removing the parameter altogether might break compatibility with old Django versions, so some crafty class construction might be necessary.

RuntimeWarning: Pickled model instance's Django version

IĀ“m getting this warning when I updated Django, what should I do? load and save all my models PickedField?

/venv/lib/python3.8/site-packages/picklefield/fields.py:78: RuntimeWarning: Pickled model instance's Django version 3.1.7 does not match the current version 3.2.6.

how can I see the PickledObjectField in the admin

First of all thank you for sharing this code. I think I've taken the appropriate steps but I can't see the field in the admin. Should I be able to see it and edit it?

models.py

from picklefield.fields import PickledObjectField # to store the curve
class Whateva(models.Model):
    pickled_curve =  PickledObjectField(_('The Curve y vs x'),
                                                             help_text=_('Insert the curve in the following format ((0,0),(1,0),(2,1),..etc,)'),)

admin.py

from django.contrib import admin
from myapp.models import Whateva

admin.site.register(Whateva)

Any tips appreciated, thank you.

Make admin editable widget a TextArea

I edit PickledObjectField's in admin using editable=True flag where the assigned widget is a textbox. So I have to add the following line to my admin class:
formfield_overrides = {PickledObjectField: {'widget': widgets.AdminTextareaWidget}, }
I think it'd be nice if this was the default behaviour.

problem subclassing and overriding from_db_value

I recently upgraded from Django 1.7 to 1.8 and have run into problems with a subclassed PickledObjectField. The code looks like this:

from picklefield.fields import PickledObjectField as OriginalPickledObjectField

class PickledObjectField(OriginalPickledObjectField):
    """ Modified to return an empty `dict` object if empty """

    def to_python(self, value):
        return super(PickledObjectField, self).to_python(value) or {}

I had some spots where the field was sometimes None/NULL but wanted to treat those as equivalent to an empty dictionary. It worked fine until I upgraded to Django 1.8 .

I saw that in 1.8 it stops using the models.SubfieldBase metaclass and instead used from_db_value. I think the existing from_db_value, which calls to_python, should be fine but the field returns as None instead of an empty dict. I tried overriding the method to call my to_python, but for some reason it doesn't even get called!

I'm totally stumped as to what's going wrong.

Strange behavior or?

# models
class Order(models.Model):
    details = PickledObjectField()

# view
data = {'test': 0}
o = Order.objects.create(details=data)
print o.details # {'test': 0}

data['test'] = 1
print o.details # {'test': 1}

Is the second print result correct?

PS: I'm have under 1year of django/python so maybe I'm missing something here.

RemovedInDjango40Warning: force_text() is deprecated in favor of force_str()

Currently a deprecation warning is raised, because force_text is due to be replaced by force_str.

venv/lib/python3.6/site-packages/picklefield/fields.py:19
  /home/********/project/venv/lib/python3.6/site-packages/picklefield/fields.py:198: RemovedInDjango40Warning: force_text() is deprecated in favor of force_str().
    value = force_text(dbsafe_encode(value, self.compress, self.protocol, self.copy))

https://github.com/gintas/django-picklefield/blob/master/picklefield/fields.py#L198

django-picklefield slow compared to a naive solution using jsonpickle

Hi, i use django-picklefield in a project of mine and noticed that it's quite slow compared to pickling an object using jsonpickle (https://github.com/jsonpickle/jsonpickle), storing the result in a TextField, and unpickling the TextField back into a Python object. Do you know what's up with that?

I don't have any benchmarks to show for at present, but i'll make some when i get a chance. Thought i'd raise the issue now, though.

Cannot use PickleField to save a QuerySet query

This is such a particular case that I do not expect it to be solved... and actually one could argue that the bug is in the Django library.

Django specifies that if you want to pickle a QuerySet, you must pickle the query
https://docs.djangoproject.com/en/3.2/ref/models/querysets/#pickling-querysets

The problem is that a query has a method "resolve_expression", and in that case, Django skip the call to get_db_prep_save.
https://github.com/django/django/blob/3.0.14/django/db/models/sql/compiler.py#L1257

get_db_prep_save in turn is supposed to call get_db_prep_value responsible for the pickling of the object
https://github.com/django/django/blob/3.0.14/django/db/models/fields/__init__.py#L819

As a result the query object is not pickled, and Django throws an error because it creates a sub select in the query, etc.

1.1.0 not available on PyPi?

Collecting django-picklefield==1.1.0
  Could not find a version that satisfies the requirement django-picklefield==1.1.0 (from versions: 0.1, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.3.0, 0.3.1, 0.3.2, 1.0.0)
No matching distribution found for django-picklefield==1.1.0

Deepcopy could be configurable

We were running into some memory issues with many large pickles being created in a loop. Other than doing really stupid things before picklefield even got the value, we noted that the deepcopy in dbsafe_encode was responsible for generating quite a bit of junk and taking quite a lot of time.

The comments inside the method say:

We use deepcopy() here to avoid a problem with cPickle, where dumps can generate different character streams for same lookup value if they are referenced differently.

This seems reasonable. But how many people are doing string lookups on the result of their pickling? It would be great if we could disable the deepcopying via another kwarg option on the field. Currently, our work around is to replicate the dbsafe_encode in our user code so that it is decoded correctly on the way back from the database.

If you're ok with the idea, I'm happy to put a PR together to address this.

v0.3.2 breaks Django 1.8.4

Since release v0.3.2, tests for my own project with Django 1.8.4 on Python 2.7 and 3.4 fail.
Tests with 1.7.10 seem unaffected.

I will have to look at the code, but from my test log it looks like all results return the integer 1, instead of the actual field value.

ModuleNotFoundError: No module named 'django' on installing dependencies

I am using wercker to build env, install dependencies and run project. Trying to use this repo, but I get an error:

Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-kx65qy6n/picklefield/setup.py", line 5, in <module>
        import picklefield
      File "/tmp/pip-build-kx65qy6n/picklefield/picklefield/__init__.py", line 3, in <module>
        import django.utils.version
    ModuleNotFoundError: No module named 'django'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-kx65qy6n/picklefield/

This error happens because on setup.py file it import pickledfield dir which is importing django module on initiation. And then I get this error.

Is there any way I can solve this issue?

SubfieldBase deprecated in 1.8, to be removed in Django 2.0

Better early than never ;) At a quick glance, supporting anything earlier than Django 1.4 (the current LTS version) doesn't seem necessary anymore, though that's just me.

Features deprecated in 1.8

SubfieldBase

django.db.models.fields.subclassing.SubfieldBase has been deprecated and will be removed in Django 2.0. Historically, it was used to handle fields where type conversion was needed when loading from the database, but it was not used in .values() calls or in aggregates. It has been replaced with from_db_value(). Note that the new approach does not call the to_python() method on assignment as was the case with SubfieldBase.

ā€” Django 1.8 Release Notes

Accessing raw serialized data

How would you access the raw serialized data stored in a PickledObjectField? I'm using it to store some relatively large chunks of data (around 100MB) and I'd like to calculate the size of this data and cache it in an additional field. But I'm not sure how to access the serialized data directly. I'm currently reserializing it and reading the size, which is quite wasteful since PickledObjectField has already done this internally.

Django 3.2 test failure due to DEFAULT_AUTO_FIELD

Django 3.2 is emitting additional warnings, which is causing two tests to fail.

[   28s] ======================================================================
[   28s] FAIL: test_mutable_default_check (tests.tests.PickledObjectFieldCheckTests)
[   28s] ----------------------------------------------------------------------
[   28s] Traceback (most recent call last):
[   28s]   File "/home/abuild/rpmbuild/BUILD/django-picklefield-3.0.1/tests/tests.py", line 243, in test_mutable_default_check
[   28s]     id='picklefield.E001',
[   28s] AssertionError: Lists differ: [<War[905 chars]001'>, <Warning: level=30, msg="Auto-created p[378 chars]42'>] != [<War[905 chars]001'>]
[   28s] 
[   28s] First list contains 1 additional elements.
[   28s] First extra element 3:
[   28s] <Warning: level=30, msg="Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.", hint="Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.", obj=<class 'tests.tests.PickledObjectFieldCheckTests.test_mutable_default_check.<locals>.Model'>, id='models.W042'>
[   28s] 
[   28s] Diff is 2280 characters long. Set self.maxDiff to None to see it.
[   28s] 
[   28s] ======================================================================
[   28s] FAIL: test_non_mutable_default_check (tests.tests.PickledObjectFieldCheckTests)
[   28s] ----------------------------------------------------------------------
[   28s] Traceback (most recent call last):
[   28s]   File "/home/abuild/rpmbuild/BUILD/django-picklefield-3.0.1/tests/tests.py", line 253, in test_non_mutable_default_check
[   28s]     self.assertEqual(Model().check(), [])
[   28s] AssertionError: Lists differ: [<Warning: level=30, msg="Auto-created pri[380 chars]42'>] != []
[   28s] 
[   28s] First list contains 1 additional elements.
[   28s] First extra element 0:
[   28s] <Warning: level=30, msg="Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.", hint="Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.", obj=<class 'tests.tests.PickledObjectFieldCheckTests.test_non_mutable_default_check.<locals>.Model'>, id='models.W042'>
[   28s] 
[   28s] - [<Warning: level=30, msg="Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.", hint="Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.", obj=<class 'tests.tests.PickledObjectFieldCheckTests.test_non_mutable_default_check.<locals>.Model'>, id='models.W042'>]
[   28s] + []

The test_settings.py file is not included in the tarball

The test_settings.py file is not listed in the included files in MANIFEST.in, as a result it is not included in the tarball, so people downloading the tarball from PyPI can't run the test suite.

Please create the MANIFEST.in file and add test_settings.py with an include directive.

Default field value not working in Django 3

For some reason after this commit in Django 3 I can no longer use default values for PickledObjectField in MySQL, I get the following error:

django.db.utils.OperationalError: (1101, "BLOB, TEXT, GEOMETRY or JSON column 'my_field' can't have a default value")

The error only occurs in MySQL 8.0.13+ (as mentioned in the commit) but the thing is that defaults has worked for me in Django 1.11-2.2 with MySQL 5.6-8.0.19 so I'm not sure why it has been constrained in Django 3.

Has anyone else had any experience with this or know a way around it?

(Maybe this is an issue more suited for Django itself but I thought I would start here since this is what I'm using for the fields that fails)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.