[Django] #25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8

10 views
Skip to first unread message

Django

unread,
Jun 22, 2015, 10:19:28 PM6/22/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
----------------------------------------------+--------------------
Reporter: sih4sing5hong5 | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I asked in [https://groups.google.com/forum/#!topic/django-
users/9KV_uzEQloA django-user]


This code can run before django 1.7
But "related_name" got an error after django 1.8

{{{
使用者表.來源: (fields.E306) The name '使用者' is invalid related_name for
field 使用者表.來源
}}}

{{{
class 來源表(models.Model):
名 = models.CharField(max_length=100)

class 使用者表(models.Model):
來源 = models.OneToOneField(來源表, related_name='使用者',
primary_key=True, null=False)
}}}

Tim Graham said "It looks like the check added in ticket #22064 may be too
strict (only allowing alphanumeric characters in related_name)."

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

Django

unread,
Jun 22, 2015, 10:43:46 PM6/22/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------

Reporter: sih4sing5hong5 | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
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 sih4sing5hong5):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I think using
{{{
re.match('^[^\W\d]\w*$', related_name)
}}}
instead of
{{{
re.match('^[a-zA-Z_][a-zA-Z0-9_]*$', related_name)
}}}

in `django/db/models/fields/related.py`

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

Django

unread,
Jun 23, 2015, 12:55:44 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 charettes):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

I think we should default to the old behavior on Py2:
`re.match('^[^\W\d]\w*$', related_name, re.unicode if six.PY3 else 0)`

While we're at it we should also replace the trailing `$` by a `\Z` to
prevent `'related_name\n'` from being accepted.

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

Django

unread,
Jun 23, 2015, 3:31:02 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 sih4sing5hong5):

I add some tests and do these in
https://github.com/django/django/pull/4911

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

Django

unread,
Jun 23, 2015, 4:10:26 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 bmispelon):

In python 3, we should probably use `str.isidentifier` [1] instead of
coding an ad-hoc regex.

[1]
https://docs.python.org/3/library/stdtypes.html?highlight=str.isidentifier#str.isidentifier

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

Django

unread,
Jun 23, 2015, 4:34:50 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 sih4sing5hong5):

How to write Unicode test like '試驗' string in python2 ?

`related_name` does not support unicode string in python2

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

Django

unread,
Jun 23, 2015, 5:55:50 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | 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 zauddelig):

I added some notes on how make the tests work on github.

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

Django

unread,
Jun 23, 2015, 8:17:25 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* severity: Normal => Release blocker


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

Django

unread,
Jun 23, 2015, 9:32:37 AM6/23/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by sih4sing5hong5):

Thank for your suggestions. I updated the PR in github..

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

Django

unread,
Jun 26, 2015, 8:30:26 AM6/26/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"d3e12c901777697b7bf08b25e2dd46f0b951db8c" d3e12c9]:
{{{
#!CommitTicketReference repository=""
revision="d3e12c901777697b7bf08b25e2dd46f0b951db8c"
Fixed #25016 -- Reallowed non-ASCII values for ForeignKey.related_name on
Python 3.
}}}

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

Django

unread,
Jun 26, 2015, 9:15:54 AM6/26/15
to django-...@googlegroups.com
#25016: The related_name of ForeignKey cannot be Unicode name after Django 1.8
-------------------------------------+-------------------------------------
Reporter: sih4sing5hong5 | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"a97e50c5e6afe0ce2a8fb2ca27c88e57611b0053" a97e50c5]:
{{{
#!CommitTicketReference repository=""
revision="a97e50c5e6afe0ce2a8fb2ca27c88e57611b0053"
[1.8.x] Fixed #25016 -- Reallowed non-ASCII values for
ForeignKey.related_name on Python 3.

Backport of d3e12c901777697b7bf08b25e2dd46f0b951db8c from master
}}}

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

Reply all
Reply to author
Forward
0 new messages