DRF get_url: generates wrong urlid for ForeignKey models
DRF's relations.get_url
resolves the urlid of a field by reversing the view and building the site url with the request object
The issue with this is that when the server is using an Nginx proxy for example (which transforms the request), or the SITE_URL
otherwise doesn't match the request url, the url returned doesn't match the urlid of the model
In !174 (merged) we override get_url
to use obj.urlid
where available, but in the case of the ForeignKey it isn't available (see tests_get and tests_save referencing this issue). In get_url
we don't have information available at the Model
the instance represents, so using Model.get_absolute_url
isn't an option with this data (obj.__dict__
during these tests is just {pk: 1}
)
We should possibly also open an issue with Django Rest Framework