Skip to content

Provide rest_framework.resolve. #2505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 5, 2015

Conversation

brandoncazander
Copy link
Contributor

Fixes #2489.

The Django 1.4.x tox tests were failing as tests.urls was empty, so I included the necessary urlpatterns from test_relations.py.

self.field.to_internal_value('/example/3/')
self.field.to_internal_value('/v1/example/3/')


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about if we put this in tests/versioning.py?
I'd also prefer if we can keep the urlpatterns isolated to the same module as the test.

@tomchristie
Copy link
Member

Coming along nicely. One inline comment there.

@tomchristie tomchristie added this to the 3.1.0 Release milestone Feb 3, 2015
@brandoncazander
Copy link
Contributor Author

@tomchristie I moved the test to the proper location and reset urls.py. I would appreciate your quick input on two things:

  1. Which inline comment are you referring to?
  2. You can see the build failing now. From my testing, in django.core.urlresolvers.RegexURLResolver urlconf_module is:
    • Django 1.4, 1.5: <module 'tests.urls' from 'django-rest-framework/tests/urls.pyc'>
    • Django 1.6, 1.7: <module 'tests.test_versioning' from 'django-rest-framework/tests/test_versioning.py'>

I'm not sure what's going on there. If you have time to take a look that would be great; otherwise, I'll continue on it tomorrow.

@@ -127,6 +132,17 @@ def reverse(self, viewname, args=None, kwargs=None, request=None, format=None, *
viewname, args, kwargs, request, format, **extra
)

def resolve(self, path, urlconf=None, request=None):
match = django_resolve(path, urlconf)
if match.namespace:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than returning a new match is it possible to just mutate the one we've gotten back?
Eg.

match = django_resolve(path, urlconf)
match.namespaces = match.namespaces[1:]
return match

@tomchristie
Copy link
Member

Issue was due to using SimpleAPITestCase, presumably not using the full urlpatterns/resolvers machinery in that case.

I've gone with a slightly simpler implementation, based on your work, where we don't both to go for a full resolve tie in. Think it's a better trade off.

@tomchristie tomchristie merged commit 030f01a into encode:version-3.1 Feb 5, 2015
@tomchristie
Copy link
Member

Thanks for all your work on this! :)

@brandoncazander
Copy link
Contributor Author

@tomchristie Thank-you! The resolve was a nice complement to reverse, but it was too much overhead for the one spot we need it right now. Sorry I wasn't available to finish off my work. :)

rpkilby pushed a commit to rpkilby/django-rest-framework that referenced this pull request Aug 7, 2017
tomchristie pushed a commit that referenced this pull request Aug 7, 2017
* Add regression test for #2505. Thanks @pySilver!

* Add regression test for #5087

* Revert "Cached the field's root and context property."

This reverts commit 7920058.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants