[Django] #26431: django.core.urlresolvers.translate_url fix

33 views
Skip to first unread message

Django

unread,
Mar 30, 2016, 6:35:26 PM3/30/16
to django-...@googlegroups.com
#26431: django.core.urlresolvers.translate_url fix
-----------------------------+---------------------------
Reporter: jekka-ua | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Keywords: translate_url
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------
There is a problem when translating urls with absent 'optional' arguments
(it's seen in test case of the patch)

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

Django

unread,
Mar 30, 2016, 6:35:46 PM3/30/16
to django-...@googlegroups.com
#26431: django.core.urlresolvers.translate_url fix
---------------------------+----------------------------

Reporter: jekka-ua | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:

Keywords: translate_url | Triage Stage: Unreviewed
Has patch: 1 | Easy pickings: 0
UI/UX: 0 |
---------------------------+----------------------------
Changes (by jekka-ua):

* Attachment "patch-stable-1.9.txt" added.

Django

unread,
Mar 30, 2016, 6:35:56 PM3/30/16
to django-...@googlegroups.com
#26431: django.core.urlresolvers.translate_url fix
---------------------------+----------------------------

Reporter: jekka-ua | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:

Keywords: translate_url | Triage Stage: Unreviewed
Has patch: 1 | Easy pickings: 0
UI/UX: 0 |
---------------------------+----------------------------
Changes (by jekka-ua):

* Attachment "patch-master.txt" added.

Django

unread,
Mar 31, 2016, 10:10:30 AM3/31/16
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+------------------------------------

Reporter: jekka-ua | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: translate_url | 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: => 1
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you please provide the patch as a pull request against master?
Unless this is a regression, it probably doesn't qualify for a backport to
1.9 (see our [https://docs.djangoproject.com/en/dev/internals/release-
process/#supported-versions supported versions policy]). Please check the
patch on Python 3 as well (`dict.iteritems()` doesn't exist there).

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

Django

unread,
Apr 3, 2016, 6:57:08 AM4/3/16
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+------------------------------------
Reporter: jekka-ua | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by knbk):

The issue here is that `resolve()` will return `None` for any optional
capture groups that aren't captured, but `reverse()` will use
`force_text()` and convert it to the literal string `'None'`. This causes
an asymmetry between `resolve()` and `reverse()`.

I think it's a better idea to treat this asymmetry as a bug, and solve it
within `reverse()`. We would discard any arguments that are `None`.
Incidentally this will allow for cleaner code when you don't know if an
optional parameter is set when you call `reverse()` or the `{% url %}`
template tag:

{{{
{% if obj.might_be_none != None %}
{% url 'my_view' obj.might_be_none %}
{% else %}
{% url 'my_view' %}
{% endif %}
}}}

vs.

{{{
{% url 'my_view' obj.might_be_none %}
}}}

I think that's a reasonably common usecase, so it would be nice to support
this cleaner syntax. Non-existent template variables will still pass an
empty string rather than `None`, so this won't hide any typos in your
template variable names.

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

Django

unread,
Apr 14, 2019, 5:26:12 AM4/14/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: assigned

Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* owner: nobody => Daniel Rios
* status: new => assigned


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

Django

unread,
May 29, 2019, 3:50:57 PM5/29/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: assigned
Component: Core (URLs) | Version: 1.9
Severity: Normal | Resolution:
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

Comment (by j-bernard):

This also affects the set_language function.
When changing language on a page with an URL pattern containing an
optional group, the empty optional part is set to none and translating the
page leads to a 404.
The bug on translation did not exist back in 1.8, not sure when it was
introduced. I'm on 2.2.

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

Django

unread,
Jun 17, 2019, 6:12:48 AM6/17/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master

Severity: Normal | Resolution:
Keywords: translate_url | 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):

* needs_better_patch: 1 => 0
* version: 1.9 => master


Comment:

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

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

Django

unread,
Jun 19, 2019, 5:39:55 AM6/19/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: assigned
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* needs_tests: 0 => 1


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

Django

unread,
Jun 24, 2019, 6:25:57 AM6/24/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: closed

Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed

Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"76b993a117b61c41584e95149a67d8a1e9f49dd1" 76b993a]:
{{{
#!CommitTicketReference repository=""
revision="76b993a117b61c41584e95149a67d8a1e9f49dd1"
Fixed #26431 -- Prevented django.urls.resolve() from returning missing
optional parameters.

Previous behavior was inconsistent with django.urls.reverse() and
caused that translate_url() created an incorrect URL when an optional
parameter was missing.
}}}

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

Django

unread,
Jun 24, 2019, 6:25:57 AM6/24/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: assigned

Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

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

In [changeset:"d640c71fa35640b4c13107c074be2f52c52ad861" d640c71f]:
{{{
#!CommitTicketReference repository=""
revision="d640c71fa35640b4c13107c074be2f52c52ad861"
Refs #26431 -- Added tests for resolving URL and translate_url() with
provided optional parameter.
}}}

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

Django

unread,
Dec 12, 2019, 8:51:25 AM12/12/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: closed

Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed

Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

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

In [changeset:"6cb30414bc0f83b49afc4cae76d4af5656effe9a" 6cb30414]:
{{{
#!CommitTicketReference repository=""
revision="6cb30414bc0f83b49afc4cae76d4af5656effe9a"
[3.0.x] Fixed #31069, Refs #26431 -- Doc'd RegexPattern behavior change in
passing optional named groups in Django 3.0.

Backport of 9736137cdc4b7528a0aca17415dc9798660eed81 from master
}}}

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

Django

unread,
Dec 12, 2019, 8:51:27 AM12/12/19
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: closed
Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------

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

In [changeset:"9736137cdc4b7528a0aca17415dc9798660eed81" 9736137]:
{{{
#!CommitTicketReference repository=""
revision="9736137cdc4b7528a0aca17415dc9798660eed81"


Fixed #31069, Refs #26431 -- Doc'd RegexPattern behavior change in passing
optional named groups in Django 3.0.
}}}

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

Django

unread,
Mar 2, 2024, 2:32:36 PMMar 2
to django-...@googlegroups.com
#26431: translate_url() creates an incorrect URL when optional named groups are
missing in the URL pattern
-------------------------------+---------------------------------------
Reporter: EugeneM | Owner: Daniel Rios
Type: Bug | Status: closed
Component: Core (URLs) | Version: dev
Severity: Normal | Resolution: fixed
Keywords: translate_url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"595738296faec582ce90f1cffef90fbb9b18384b" 59573829]:
{{{#!CommitTicketReference repository=""
revision="595738296faec582ce90f1cffef90fbb9b18384b"
Refs #26431 -- Added more test for translated path().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26431#comment:11>
Reply all
Reply to author
Forward
0 new messages