-
Notifications
You must be signed in to change notification settings - Fork 269
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
Problems withs PostGres 9.3, JSON Field and Query Distinct #57
Comments
@ewjoachim do you have a test case by chance I could use to build a fix on top of? Not easily able to re-produce the issue on my end. |
Got the same error by doing a distinct or an annotate on a field that has a json field. Edit : It seems this guy runs into the same problem : http://stackoverflow.com/questions/19117933/django-db-error-could-not-identify-an-equality-operator-for-type-json-when-tryi |
After updating to Postgresql 9.3, I was getting failing tests because the jsonfield package was trying to use the native Postgres 'json' type, but something was failing. A close-enough issue is here: rpkilby/jsonfield#57. Until this is fixed, I'm pointing to a fork that provides a simple fix for this where we go back to pre-Postgres 9.2 behavior pretending we don't have a special json field.
This is probably related: I tried running the OrderedDictSerializationTest class which came in the out-of-the-box tests.py for 0.9.20. I'm using Postgres 9.3.2 and Django 1.5. The class creates the OrderedDict, but I get "no tests were found" in my (PyCharm) TestRunner. Also, "print" commands at the start of the test_*() methods don't execute. (Traceback below.) I tried commenting out the db_type function in JSONFieldBase and that worked better.
|
I had this issue popping up in Admin list views for models that contained JSON columns (even though I wasn't showing those field in the view). Interestingly enough, when the view is called, it doesn't actually call the def get_queryset(self):
"""
Returns a new QuerySet object which excludes JSON `key_values` column.
"""
return QuerySet(self.model, using=self._db).defer('key_values') |
Solved my case.
Hope, this helps to somebody |
when will you release a version that gets rid of the Postgres JSON column ? |
@diwu1989 you can use the branch at https://github.com/bradjasper/django-jsonfield/tree/postgresql for now which is supported and kept up-to-date with master. Will likely be making it a official release soon. |
I have tried to install the postgresql version from github, but I keep getting error code 128 in none. Do you know when you will be merging the two branches? Or can you post instructions to manually install from github. |
The PostgreSQL change has been merged into master and the version has been bumped to 1.0.0. This is a backwards incompatible change for anyone using PostgreSQL & django-jsonfield 0.9.x. |
If I understand correctly, it should be completely ok to upgrade jsonfield to 1.0.0 if I have never created JSONFields in PostgreSQL 9.2+, correct? i.e. |
@ksze this looks right. The easiest way to be sure is to look at your column type in the database. If it's "text" you're ok. If it's "json" then it needs to be migrated or you should stick to an older version of django-jsonfield. |
Hi, I'm interested in updating to 1.0.0 but I am using postgres 9.3 and have models with the json column type from before the change. If I update to 1.0.0 and run I am quite new to Django/South and migrations, are there any recommendations for how best to handle this case? Cheers, |
@michaeljones Using Django/South migrations is a little weird for this situation because you would then need to consider what happens when you run your whole suite of migrations on a pristine database (e.g. during Instead, you may want to do it with some raw, throw-away SQL:
WARNING: try this in a snapshot of your database first! |
@ksze Thank you for such a quick response. I see now how South migrations would be the wrong approach. Thank you for pointing that out. I will try my hand at raw, throw-away SQL then :) Much appreciated! |
If anyone of my level comes by, here is what I used: ALTER TABLE "myapp_mymodel"
ALTER COLUMN "myfield" TYPE text,
ALTER COLUMN "myfield" SET NOT NULL,
ALTER COLUMN "myfield" DROP DEFAULT; So for the ALTER TABLE "organisations_organisation"
ALTER COLUMN "links" TYPE text,
ALTER COLUMN "links" SET NOT NULL,
ALTER COLUMN "links" DROP DEFAULT; You can make an $ ./manage.py dbshell
psql (9.3.5)
SSL connection (...)
Type "help" for help.
dbname=# \i sql/change-json-fields-to-text.sql Where If anyone more experienced comes along, please point out anything that is wrong. The sql comes from a verbose output of a South migration which represents the change I was after. I think that postgresql knows how to cast data from Edit: I thought I has something wrong as some of the new text fields seem to have json data with an extra level of quoting, but as this has happened to only some and not all the rows, I assume there is something wrong with my data which doesn't surprise me in this instance. |
If I might, the |
@Xowap I'd be open to taking another look at this now that it looks like some of the support in django has been improved. Plan is to schedule some work on this in the next couple of weeks and this is something I can look at. |
Any updates on getting support for using the native |
Leaving out jsonfield 1.03 until I can wrap my head around PostgreSQL issue: rpkilby/jsonfield#57
Hi @bradjasper any news on jsonb support? |
It might be a problem if you cannot easily upgrade Django, but jsonb is natively supported by 1.9 https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield |
As mentionned in #47, using ".distinct()", which is used by the admin panel creating users but also in several other cases in django processes, triggers the same bug as #47 describes.
A workaround has been found by @mkhattab :
The work around for this in the Django admin is to subclass
QuerySet
andManager
and override thedistinct
method [to remove the JSON fields from it].What would be the definite fix ?
The text was updated successfully, but these errors were encountered: