Re: [Django] #35431: Failing to serialize NumericRange with CheckConstraint on IntegerRangeField

2024-05-05 Thread Django
#35431: Failing to serialize NumericRange with CheckConstraint on 
IntegerRangeField
+--
 Reporter:  Arran   |Owner:  nobody
 Type:  Bug |   Status:  closed
Component:  Migrations  |  Version:  5.0
 Severity:  Normal  |   Resolution:  invalid
 Keywords:  | Triage Stage:  Unreviewed
Has patch:  0   |  Needs documentation:  0
  Needs tests:  0   |  Patch needs improvement:  0
Easy pickings:  0   |UI/UX:  0
+--
Changes (by Mariusz Felisiak):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 You need to add `django.contrib.postgres` to the `INSTALLED_APPS` this
 will register PostgreSQL-specific serializers.
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f49304fe9-8a5e722f-00f1-4b21-918f-d2f680f313ed-00%40eu-central-1.amazonses.com.


[Django] #35431: Failing to serialize NumericRange with CheckConstraint on IntegerRangeField

2024-05-04 Thread Django
#35431: Failing to serialize NumericRange with CheckConstraint on 
IntegerRangeField
--+
   Reporter:  Arran   |  Owner:  nobody
   Type:  Bug | Status:  new
  Component:  Migrations  |Version:  5.0
   Severity:  Normal  |   Keywords:
   Triage Stage:  Unreviewed  |  Has patch:  0
Needs documentation:  0   |Needs tests:  0
Patch needs improvement:  0   |  Easy pickings:  0
  UI/UX:  0   |
--+
 I am trying to create a PostgreSQL check constraint on an
 `IntegerRangeField`, but when I run `makemigrations` I get the following
 error:

 {{{
 ValueError: Cannot serialize: Range(1, 1, '[)')
 There are some values Django cannot serialize into migration files.
 }}}

 Here's a simple example of my model which raises the error:

 {{{
 from django.contrib.postgres.fields import IntegerRangeField
 from django.db.backends.postgresql.psycopg_any import NumericRange
 from django.db import models
 from django.db.models.constraints import CheckConstraint
 from django.db.models.expressions import Q


 class MyModel(models.Model):
 price_range = IntegerRangeField()

 class Meta:
 constraints = [
 CheckConstraint(
 check=Q(price_range__contained_by=NumericRange(1, 1)),
 name="price_range_gt_1_and_lte_1",
 )
 ]
 }}}

 Judging by the following ticket this should work, so any help would be
 welcome:

 [https://code.djangoproject.com/ticket/30258]

 Thanks!
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f43a6a863-f7ead347-c8ac-4218-991d-3c2689b52eb4-00%40eu-central-1.amazonses.com.