Giter VIP home page Giter VIP logo

Comments (11)

kevin-brown avatar kevin-brown commented on August 12, 2024

This is because your tests and people/(?P<parent_lookup_person__uuid>[^/.]+)/tests views both have the same base_name of test. You can tell because both of them are (incorrectly) pointing to the same url, and the first one is not triggering an error.

The ExtendedDefaultRouter depends on the first one triggering a reverse error, so it can be excluded from the output.

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

I saw that the URL was duplicated. This does not fully explain the issue, however.

In[5]: reverse('test-list')
Out[5]: '/api/tests/'
In[7]:  reverse('test-list', kwargs={'parent_lookup_person__uuid':'alex'})
Out[7]: '/api/people/alex/tests/'

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

Either way, the nested item should not be exposed at the top level (ie root view). The only reason this works when changing the base name is:

                for key, url_name in api_root_dict.items():
                    try:
                        ret[key] = reverse(url_name, request=request, format=format)
                    except NoReverseMatch:
                        pass

where key is people/(?P<parent_lookup_person__uuid>[^/.]+)/tests and url_name is <base_name>-list.

Changing the base_name to something else causes NoReverseMatch to be raised so the item is silently hidden from the root view.

There is no reason that base_name should not be able to be set to the same value for both levels.

Right now I am trying to move to drf-extensions from https://github.com/alanjds/drf-nested-routers and I had been able to use the same base_name without an issue before.

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

The issue here is that register called on NestedRegistryItem adds to the registry of the underlying router rather than keeping a separate list of sub URLs.

from drf-extensions.

kevin-brown avatar kevin-brown commented on August 12, 2024

This does not fully explain the issue, however...

Yes, multiple routes can share the same name and take in different arguments.

Changing the base_name to something else causes NoReverseMatch to be raised so the item is silently hidden from the root view.

This is intentional and it was added in #14. I don't know of a better way to handle it, but I'm sure a pull request would be reviewed if it came in.

Right now I am trying to move to drf-extensions from https://github.com/alanjds/drf-nested-routers and I had been able to use the same base_name without an issue before.

If I remember correctly, drf-nested-routers did not support the DefaultRouter and using the one provided by DRF should have had the same issue.

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

@kevin-brown I think the root cause for all of this is: #57 (comment)

That is implicitly how drf-extensions deals with the issue: it does NOT add all of the routes to the base router but required you to add those routers individually.

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

@kevin-brown Any more thoughts on this?

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

@kevin-brown Thoughts?

from drf-extensions.

kevin-brown avatar kevin-brown commented on August 12, 2024

@cancan101 looks like it's up to @chibisov.

For what it's worth, you'd have this issue without the custom router now that DRF also has the try...except code in place.

from drf-extensions.

cancan101 avatar cancan101 commented on August 12, 2024

@kevin-brown:

The issue here is that register called on NestedRegistryItem adds to the registry of the underlying router rather than keeping a separate list of sub URLs.

This is different from how drf-nested-routers works where each nested router keeps track of the URLs (routes) at its level.

from drf-extensions.

auvipy avatar auvipy commented on August 12, 2024

closing

from drf-extensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.