#34515: Translatable URL patterns raise 404 for non-English default language when prefix_default_language=False is used. -------------------------------------+------------------------------------- Reporter: ab | Owner: Sarah | Boyce Type: Bug | Status: closed Component: | Version: 4.2 Internationalization | Severity: Release blocker | Resolution: fixed Keywords: | Triage Stage: Accepted internationalization, i18n, | prefix_default_language, | i18n_patterns | Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Comment (by Foucauld Degeorges):
Quite logically, this fix recreated the previous bug [https://code.djangoproject.com/ticket/32886]. A summary of my understanding of the issue: The root cause seems to be that in an app where the following routes coexist: - type A: a language-independant route. The language cannot be inferred from calling such routes. - type B: a language-dependant route, with a prefix from `i18n_patterns`, with `prefix_default_language=False`. The language can be inferred from calling such routes, and will supersede other sources of language. `LocaleMiddleware` cannot tell those apart. With the code currently on master, `LocaleMiddleware` detects that at least one URL of type B exists in the app, and will assume that all routes of type A or B are of type B. It will always choose to infer the language. If I understand correctly, the PR that fixed that other bug, simply inverted the behaviour and created this bug here. Reverting that PR recreated the old bug. The actual fix would be for `LocaleMiddleware` to be able to know whether the ''specific route'' is of type A or B, and based on that, choose to infer the language of the request or not. As a workaround, we have implemented our own `LocaleMiddleware` which: - uses logic adapted from `django-extensions`' `show_urls` command to list all routes in all activated languages - groups them by name to see whether some routes have more than one distinct pattern - this tells us whether a route is translated (of type B), or not translated (of type A) - if type B, `LocaleMiddleware` should infer the language from the route. If type A, it shouldn't. -- Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:19> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/django-updates/01070196dd8f4f64-904147ac-b220-4a2f-8493-3ddfe011da07-000000%40eu-central-1.amazonses.com.