[Django] #31742: Not working model on 3.1 (lazy reference)

38 views
Skip to first unread message

Django

unread,
Jun 25, 2020, 1:49:23 AM6/25/20
to django-...@googlegroups.com
#31742: Not working model on 3.1 (lazy reference)
--------------------------------------------+------------------------
Reporter: Ignacio Santolin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
When i run "python3 manage.py migrate" on Django 3.1b1 shows me that error
**(Please, note that the code works well in 3.0)**


{{{
ValueError: The field DJ_RegLogin.Content.category was declared with a
lazy reference to 'dj_reglogin.category', but app 'dj_reglogin' isn't
installed.
}}}

model.py (Conflict Part)
{{{
class Category(models.Model):
title = models.CharField(max_length=100, db_index=True)
slug = models.SlugField(max_length=100, db_index=True)

class Meta:
verbose_name = 'Category'
verbose_name_plural = 'Categories'

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('view_blog_category', None, kwargs={'slug':
self.slug})


class Content(models.Model):
title = models.CharField(max_length=100, unique=True)
slug = models.SlugField(max_length=100, unique=True)
body = RichTextField(config_name='default')
posted = models.DateTimeField(db_index=True, auto_now_add=True)
sites = models.ManyToManyField(Site)
ip = models.GenericIPAddressField(editable=False)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False,
blank=False, editable=False)
status = models.CharField(max_length=10, choices=STATUS_CHOICES,
default='draft')

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('view_blog_post', None, kwargs={'slug': self.slug})
}}}

settings.py (Related to issue part)

{{{
INSTALLED_APPS = [
'DJ_RegLogin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'social_django',
'ckeditor',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.sitemaps',
]
}}}


apps.py
{{{
from django.apps import AppConfig


class DJ_RegLoginConfig(AppConfig):
name = 'DJ_RegLogin'
verbose_name = "Contents"
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31742>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 25, 2020, 5:01:28 AM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------

Reporter: Ignacio Santolin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by felixxm):

* cc: Adam (Chainz) Johnson (added)
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

Regression in 9e1b6b8a66af4c2197e5b1b41eb9dbb36e4f6502.
Reproduced at fbe82f82555bc25dccb476c749ca062f0b522be3.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:1>

Django

unread,
Jun 25, 2020, 5:15:23 AM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by felixxm):

Potential fix:
{{{
diff --git a/django/db/models/fields/related.py
b/django/db/models/fields/related.py
index d517d7269b..894d931d50 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -582,7 +582,8 @@ class ForeignObject(RelatedField):
if self.remote_field.parent_link:
kwargs['parent_link'] = self.remote_field.parent_link
if isinstance(self.remote_field.model, str):
- kwargs['to'] = self.remote_field.model.lower()
+ app_label, model_name = self.remote_field.model.split('.')
+ kwargs['to'] = '%s.%s' % (app_label, model_name.lower())
else:
kwargs['to'] = self.remote_field.model._meta.label_lower
# If swappable is True, then see if we're actually pointing to
the target
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:2>

Django

unread,
Jun 25, 2020, 5:36:55 AM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Adam (Chainz) Johnson):

That fix looks good to me.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:3>

Django

unread,
Jun 25, 2020, 12:46:53 PM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by felixxm):

* owner: nobody => felixxm
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:4>

Django

unread,
Jun 25, 2020, 2:21:43 PM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Simon Charette):

Wonder if a longer term solution is to use case insensitive identifier for
app labels as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:5>

Django

unread,
Jun 25, 2020, 3:32:41 PM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by felixxm):

Replying to [comment:5 Simon Charette]:


> Wonder if a longer term solution is to use case insensitive identifier
for app labels as well.

Maybe, I'm afraid that it will create some regressions, since app labels
were always 🤔 case sensitive in migrations . This small patch should be
fine for backport.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:6>

Django

unread,
Jun 25, 2020, 9:09:56 PM6/25/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Simon Charette):

Agreed, safer to stick to the less intrusive backport for the time being.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:7>

Django

unread,
Jun 26, 2020, 12:52:21 AM6/26/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13112 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:8>

Django

unread,
Jun 26, 2020, 6:45:00 AM6/26/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: assigned
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Adam (Chainz) Johnson):

Case insensitive app labels would make sense. PEP8 recommends lowercase
only module names, and using mixing case in filenames can be fraught with
errors between different filesystems where case sensitivity in comparisons
and naming varies widely.

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:9>

Django

unread,
Jun 26, 2020, 5:19:16 PM6/26/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: closed
Component: Migrations | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"62d85a283500e9abb0e1c9ec53c59be468f056a0" 62d85a2]:
{{{
#!CommitTicketReference repository=""
revision="62d85a283500e9abb0e1c9ec53c59be468f056a0"
Fixed #31742 -- Fixed makemigrations crash on ForeignKey to an app with
mixed case label.

Regression in 9e1b6b8a66af4c2197e5b1b41eb9dbb36e4f6502.

Thanks Ignacio Santolin for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:10>

Django

unread,
Jun 26, 2020, 5:21:24 PM6/26/20
to django-...@googlegroups.com
#31742: makemigrations crashes for ForeignKey with mixed-case app name.
----------------------------------+------------------------------------
Reporter: Ignacio Santolin | Owner: felixxm
Type: Bug | Status: closed
Component: Migrations | Version: 3.1

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"5263480d7f04ffdb845c37770680d605f1306f7c" 5263480d]:
{{{
#!CommitTicketReference repository=""
revision="5263480d7f04ffdb845c37770680d605f1306f7c"
[3.1.x] Fixed #31742 -- Fixed makemigrations crash on ForeignKey to an app
with mixed case label.

Regression in 9e1b6b8a66af4c2197e5b1b41eb9dbb36e4f6502.

Thanks Ignacio Santolin for the report.

Backport of 62d85a283500e9abb0e1c9ec53c59be468f056a0 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31742#comment:11>

Reply all
Reply to author
Forward
0 new messages