I have a pretty simple model:
from django.contrib.postgres.fields import IntegerRangeField
from django.db import models
class Production(models.Model):
title = models.CharField(max_length=100, blank=True, db_index=True)
year = models.PositiveSmallIntegerField(blank=True, default=0, db_index=True)
index = models.PositiveSmallIntegerField(blank=True, default=0)
run_years = IntegerRangeField(blank=True, null=True)
class Meta:
unique_together = ('title', 'year', 'index')
But, I'm experiencing a very strange behavior when I'm manipulating my model through update_or_create
method. For some reason my IntegerRange
field gets just wiped.
In [1]: Production.objects.update_or_create(**{'title': '#twentyfiveish', 'year': 2017,
'index': 0, 'run_years': (2017, 2017)})[0].run_years
Out[1]: (2017, 2017)
In [2]: Production.objects.update_or_create(**{'title': '#twentyfiveish', 'year': 2017,
'index': 0, 'run_years': (2017, 2017)})[0].run_years
Out[2]: NumericRange(empty=True)
That doesn't look as a desired behavior to me. Is it a bug or not? Please advise.
Versions:
- Django 1.11
- PostgreSQL 9.6.3