Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

related_url doesn't get added if no kwargs #273

Open
fhriley opened this issue Dec 4, 2019 · 3 comments
Open

related_url doesn't get added if no kwargs #273

fhriley opened this issue Dec 4, 2019 · 3 comments

Comments

@fhriley
Copy link

fhriley commented Dec 4, 2019

If you have a relationship with a related url of /foo/bar, you specify the relationship in the schema like this:

bar = fields.Relationship(
    related_url="/foo/bar",
    type_="bar",
)

This will never add the related URL to the output due to the following check in the code:

Instead, this code should do the following:

if non_null_params:
    return self.related_url.format(**non_null_params)
else:
    return self.related_url

This makes more sense because we've already checked that the related_url was specified:

and it doesn't make sense to just ignore it.

@multimeric
Copy link

Although you seem to be right about this behaviour, I wonder what the point is of having a relationship that doesn't use any kwargs. Normally the related URL would be /posts/1/comments, or /authors/1 , both of which use an argument. What is your use-case for a hard-coded URL?

@fhriley
Copy link
Author

fhriley commented Dec 4, 2019

It is a one to one relationship and there will never be more than one. For example, there is one 10 GigE interface and that interface has one SFP, which is in the API as /xgige/sfp. This is much cleaner than having /xgiges/1/sfps/1, which also doesn't make sense to clients of the api since there aren't multiple interfaces.

@multimeric
Copy link

Yeah okay I think that makes sense. Should be an easy fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants