#25016 closed Bug (fixed)
The related_name of ForeignKey cannot be Unicode name after Django 1.8
Reported by: | A-hông | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
I asked in 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)."
Change History (10)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
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.
comment:3 by , 9 years ago
I add some tests and do these in https://github.com/django/django/pull/4911
But how to write Unicode test like '試驗' string in python2 ?
related_name
does not support unicode string in python2
comment:4 by , 9 years ago
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
comment:5 by , 9 years ago
How to write Unicode test like '試驗' string in python2 ?
related_name
does not support unicode string in python2
comment:7 by , 9 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Severity: | Normal → Release blocker |
I think using
instead of
in
django/db/models/fields/related.py