Skip to content
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

DRF shows wrong URL at apiroot if different applications have models with the same name #8829

Closed
Credentive-Sec opened this issue Jan 4, 2023 Discussed in #8824 · 1 comment

Comments

@Credentive-Sec
Copy link

Discussed in #8824

Originally posted by Credentive-Sec December 31, 2022
I have a dango project with three applications. Two of them have Models called "Review Comment". The models are identical, but the different applications show different objects based on filtering - note that the Models for the apps are maintained in separate tables in the database, since they are in different applications

I have set up separate Serializers and ViewSets - the view sets apply proper filtering.

in the project's url.py I have the following code (snippet):

import compliancemanager.views as cc_views
import reviewmanager.views as rm_views

compliancemanager_router = routers.DefaultRouter()
compliancemanager_router.register(r"compliance_statement_responses", cc_views.ComplianceStatementResponseViewSet)
compliancemanager_router.register(
    r"compliance_manager_review_comments", cc_views.ComplianceManagerReviewCommentViewSet
)
# Registered ViewSets - review manager
reviewmanager_router = routers.DefaultRouter()
reviewmanager_router.register(r"compliance_statement_reviews", rm_views.ComplianceStatementReviewViewSet)
reviewmanager_router.register(r"review_manager_review_comments", rm_views.ReviewCommentViewSet)

these views show "ComplianceStatementReview" objects and "ReviewComment" objects for each of their applications.

When I visit the review manager HTML render page in DRF, I see the following:
"review_manager_review_comments": "http://localhost:8000/reviewmanager/api/v1/review_manager_review_comments/"

When I visit the compliance manager HTML Render page in DRF, I see the following:
"compliance_manager_review_comments": "http://localhost:8000/**reviewmanager**/api/v1/review_manager_review_comments/"
Note the the compliance manager HTML page refers to the review manager URL

If I manually visit the appropriate URL,
http://localhost:8000/compliancemanager/api/v1/compliance_manager_review_comments/

I see the expected data, so the issue is just api_root. I have confirmed that the same behavior occurs on the JSON rendered page, so it's not an issue with the HTML interface.

After experimenting with a lot of different changes, I have notice that the issue is caused because the Models in the application have the same name. If I change the model name in the application, the URL is rendered correctly.

I can change the model name, but I still think this is probably a bug.

Happy to provide more code and detail if needed.

@auvipy
Copy link
Member

auvipy commented Jan 4, 2023

check in the discussion. and #8438

@auvipy auvipy closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant