﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34059	Validation of check constraints on postgres json fields produce invalid SQL	Dan LaManna		"Given a model with constraints within the JSONField:


{{{

class Version(models.Model):
    metadata = models.JSONField(blank=True, default=dict)

    class Meta:
        constraints = [
            models.CheckConstraint(
                name='version_metadata_has_schema_version',
                check=~Q(metadata__schemaVersion=None),
            )
        ]
}}}



The following code produces an error:
{{{
version = Version(metadata={'foo': 'bar'})
version.validate_constraints()
}}}

{{{
WARNING  Got a database error calling check() on <Q: (AND: (NOT (AND: ('metadata__schemaVersion', None))))>: operator is not unique: unknown -> unknown         
                    LINE 1: SELECT 1 AS ""_check"" WHERE NOT (('{""foo"": ""bar""}' -> 'schema...                                                                                                  
                                                                              ^                                                                                                              
                    HINT:  Could not choose a best candidate operator. You might need to add explicit type casts
}}}

Internally it's running the following query:
{{{
SELECT 1 AS ""_check""
 WHERE NOT (('{""foo"": ""bar""}' -> 'schemaVersion') = 'null')
}}}

This appears similar to https://code.djangoproject.com/ticket/33905."	Bug	new	contrib.postgres	4.1	Normal				Unreviewed	0	0	0	0	0	0
