Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Resolving APIs URL to different namespaces#3816
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
xordoquy commentedJan 15, 2016
Open question, would it be worth to alter the tests so they include one model in common and make sure it's resolved correctly for each namespace ? |
xordoquy commentedJan 15, 2016
I wonder if some of the code can't be factorized with Django's. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd really like to see an explicit raise here.
This syntax will work as long asno other exception is being thrown - no matter whether they are caught or not.
Given the code quantity between the initial except and this line it's subject to caution imho.
xordoquy commentedJan 15, 2016
OK, with the restriction on the raise statement it looks good to me. |
xordoquy commentedJan 15, 2016
Use case that may lead to raising the wrong exception:
Guess what raise will raise when url is None ? Is that use case possible ? NB: >>>try:...0/0...exceptException:...try:...'a'+1...exceptTypeError:...pass...raise...Traceback (mostrecentcalllast):File"<stdin>",line5,in<module>TypeError:cannotconcatenate'str'and'int'objects>>> |
lovelydinosaur commentedFeb 15, 2016
My super quick review --> I can see a lot of code, and not much explanation. What caseexactly is being resolved here? If there's any other kind of workaround or the case isn't 100% clear cut then I'm unlikely to be in favor of this change. |
xordoquy commentedMar 2, 2016
The point I don't get here is why it does try every namespace if it can't resolve without namespace or with the current namespace. |
debnet commentedMar 2, 2016
For example, in a case when a model from an application under a namespace references another application model under a different namespace. |
nwp90 commentedJan 4, 2017
I don't see how#4219 justifies closing this. This has nothing to do with versioning. If a namespace is in use, it would be nice for HyperlinkedModelSerializers to continue to function, at least where the linked detail route is in the same namespace as the current request. I'm not sure what the right thing to do is when it's in a different namespace - it's conceivable that the current app would know about a subtree of the overall namespace but not the whole thing. e.g. app with routes under "foo:api:firstapp" knows about the "api:firstapp" portion of the namespace, and that the model it's after is in "api:otherapp", but not that that is also now under the top-level "foo" namespace. Seems to me that it would be desirable to infer a prefix based on what is expected and experienced (expect to be in "api:firstapp" but discover that we're in "foo:api:firstapp", so infer "foo" prefix), and then use that to help find other known routes. |
debnet commentedJan 4, 2017
In my use-case, the current version doesn't solve the problem. I still have to deal with models referencing each others through differents namespaces myself. Fortunatly,@xordoquy gives me the evidence that my previous solution have some caveats and can lead to undesired behaviour. Since, I changed the whole implementation of |
nwp90 commentedJan 4, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
For the moment I'm working around this with: i.e. the serializer now knows which namespace it's in, and can pass this through to the fields. If a field is referring to an object in a different namespace, I have to specify that on the field. |
nwp90 commentedJan 4, 2017
Oh, I've added get_extra_kwargs as below, to allow setting those prefixes from the serializer's Meta class too: |
lovelydinosaur commentedJan 5, 2017
Can't we enforce explicitly namespaced view names in this case rather than magically inferring them? |
debnet commentedJan 5, 2017
It depends how you want use your viewsets. In my case, we have a framework above our project in order to dynamically generate APIs from models with all filters, orders, related models and prefetchs... so having to deal with namespaces could lead to a lot of redundant work. Nevertheless, I understand your point of view: explicit is better than implicit. But I guess through this issue I'm not alone to require that kind of feature. :) |
nwp90 commentedJan 8, 2017
You can't be explicit when you don't know thefull namespace a pluggable app might be included under. |
An enough tested revision in order to allow resolving APIs URL using APIs in different namespaces.
Used as a patch in production environment since about one year without issue.
See#1495