{"action":"created","issue":{"url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/7","labels_url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/7/comments","events_url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/7/events","html_url":"https://github.com/django-oscar/django-oscar-api/pull/7","id":57635415,"number":7,"title":"Remove locale from url","user":{"login":"maerteijn","id":121401,"avatar_url":"https://avatars.githubusercontent.com/u/121401?v=3","gravatar_id":"","url":"https://api.github.com/users/maerteijn","html_url":"https://github.com/maerteijn","followers_url":"https://api.github.com/users/maerteijn/followers","following_url":"https://api.github.com/users/maerteijn/following{/other_user}","gists_url":"https://api.github.com/users/maerteijn/gists{/gist_id}","starred_url":"https://api.github.com/users/maerteijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maerteijn/subscriptions","organizations_url":"https://api.github.com/users/maerteijn/orgs","repos_url":"https://api.github.com/users/maerteijn/repos","events_url":"https://api.github.com/users/maerteijn/events{/privacy}","received_events_url":"https://api.github.com/users/maerteijn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-13T18:27:55Z","updated_at":"2015-02-16T10:54:13Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/django-oscar/django-oscar-api/pulls/7","html_url":"https://github.com/django-oscar/django-oscar-api/pull/7","diff_url":"https://github.com/django-oscar/django-oscar-api/pull/7.diff","patch_url":"https://github.com/django-oscar/django-oscar-api/pull/7.patch"},"body":"When i18n is enabled in Django it sometimes occures that `reverse('root-api')` returns an url including a different locale then the current locale. Why this happens is unknown, it's something in the i18n code in Django and it's really hard to reproduce.\r\n\r\nThe problem is that when it occurs, the `is_api_request()` call returns False, so the session which is build up by the `Session-Id` header is not resumed, instead a normal django session is initiated. When you retrieve your basket using the API you will get a different one as it cannot find it in your (already existing) session (which is created using the middleware).\r\n\r\nSee this debug log what happens:\r\n```\r\nDEBUG 2015-02-13 11:41:20,639 middleware >> NO API request -> path:/nl-nl/api/basket/ api_root:/fr-be/api/\r\nDEBUG 2015-02-13 11:41:20,639 middleware >> NO API request, using normal session middleware\r\nDEBUG 2015-02-13 11:41:20,652 abstract_models Session basket info:SID:ANON:shop-api.myshop.com:{cfa69238-4f46-47d6-9ed8-0f8a75e14eee} -> key:None contents:{}\r\n```\r\nThe session key will result in `None` so it won't return the correct basket.\r\n\r\nAs the locale is irrelevant to check if it's an api request, this code will remove the language from the url's prior to comparison."},"comment":{"url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/comments/74490681","html_url":"https://github.com/django-oscar/django-oscar-api/pull/7#issuecomment-74490681","issue_url":"https://api.github.com/repos/django-oscar/django-oscar-api/issues/7","id":74490681,"user":{"login":"maerteijn","id":121401,"avatar_url":"https://avatars.githubusercontent.com/u/121401?v=3","gravatar_id":"","url":"https://api.github.com/users/maerteijn","html_url":"https://github.com/maerteijn","followers_url":"https://api.github.com/users/maerteijn/followers","following_url":"https://api.github.com/users/maerteijn/following{/other_user}","gists_url":"https://api.github.com/users/maerteijn/gists{/gist_id}","starred_url":"https://api.github.com/users/maerteijn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maerteijn/subscriptions","organizations_url":"https://api.github.com/users/maerteijn/orgs","repos_url":"https://api.github.com/users/maerteijn/repos","events_url":"https://api.github.com/users/maerteijn/events{/privacy}","received_events_url":"https://api.github.com/users/maerteijn/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T10:54:13Z","updated_at":"2015-02-16T10:54:13Z","body":"I think you're right. The only way I can think of how to do this simple and clean is to move the `is_api_request` method into the Middleware class, so we can create a custom middleware in which we only override this method. Your thoughts?"}}