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

Regression: GET_SINGLE requests to parent class do not find instances of child classes #614

Open
Natureshadow opened this issue Dec 13, 2016 · 5 comments
Labels

Comments

@Natureshadow
Copy link
Contributor

Natureshadow commented Dec 13, 2016

Considering having a model called A and a model called B, where B is a sublcass of A, there is an issue with getting single resources. A and B are polymorphic in SQLAlchemy.

GETing /api/A returns a list of all instances of A and B, but GETing /api/A/1 returns 404 if the object with id 1 is an instance of class B.

It should be possible to get resources of a child model by GETing it through the parent model endpoint.

@Natureshadow Natureshadow changed the title GET_SINGLE requests to parent lcass to not find instances of child classes GET_SINGLE requests to parent class do not find instances of child classes Dec 13, 2016
@Natureshadow
Copy link
Contributor Author

This used to work in 0.17.0 by the way.

@Natureshadow Natureshadow changed the title GET_SINGLE requests to parent class do not find instances of child classes Regression: GET_SINGLE requests to parent class do not find instances of child classes Dec 13, 2016
@jfinkels
Copy link
Owner

This is a design decision I made in order for the different request methods (GET, POST, etc.) to be more uniform and to fit more cleanly with the requirements of the JSON API specification. See #200 (comment) for a summary of what is supported and what is not supported.

Basically, if we allow fetching from /api/A/1 then the response will be a JSON API resource object of type B: {'id': 1, 'type': 'B'}. Now what should its self URL be? Should requests to /api/B/1 be allowed? etc. There are many small issues like this, and I'm happy to receive advice on how to handle them.

@jfinkels jfinkels added the bug label Dec 15, 2016
@Natureshadow
Copy link
Contributor Author

I think as /api/A lists the resource, then it should also be available as /api/A/1. You either recognize as also being an instance of A or you don't, but you don't accept that it is of class A in GET_MANY, then deny it in GET_SINGLE.

its self link should probably point to the real type URL (it does so when being listed in /api/A, right?).

That would also match the polymorphism in SQLAlchemy.

@Natureshadow
Copy link
Contributor Author

Natureshadow commented Dec 15, 2016

Maybe it's even simpler, and you should really just rely on how SQLAlchemy is configured. That is, if the resource can be found by A.get(1) in Flask-SQLAlchemy, then Flask-Restless should deliver it. As this is nothing that would violate JSONAPI, Flask-Restless should choose to just not divert from Flask-SQLAlchemy's behaviour.

@jfinkels
Copy link
Owner

I guess following SQLAlchemy's lead makes sense. Let's first locate the relevant test cases that need to change in tests/test_polymorphism.py, then work from there.

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

No branches or pull requests

2 participants