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

Sparse fieldsets for invalid type results in 500 #64

Open
ddobson opened this issue Jan 27, 2022 · 0 comments
Open

Sparse fieldsets for invalid type results in 500 #64

ddobson opened this issue Jan 27, 2022 · 0 comments

Comments

@ddobson
Copy link
Contributor

ddobson commented Jan 27, 2022

Description
When attempting to use sparse fieldsets for an invalid type, a 500 is raised. Is this the correct functionality? I would think this is more of a 400 level error. To demonstrate, if one were to make a request for GET /cars?fields[dealership]=name using the code below, they would get the documented 500 response. I would be happy to open a PR to change this functionality if there is agreement that there is a better way to handle these errors (i.e. raise 4XX error).

Problematic Code

raise Exception("Couldn't find schema for type: {}".format(resource_type))

Example

# Example
class Car(Base):
    id = Column(Int, primary_key=True)
    make = Column(Str)
    model = Column(Str)

class CarSchema
    class Meta:
        type_ = "car"

    make = fields.Str()
    model = fields.Str()

class CarListResource(ResourceList):
    methods = ["GET"]
    schema = CarSchema
    data_layer = {"session": db.session, "model": Car}

app = Flask(__name__)
api = Api(app)
api.route(
    CarListResource, "car_resource", "/cars",
)

Example Response

// GET /cars?fields[dealership]=name`
// status code: 500

{
  "errors": [
    {
      "status": "500",
      "title": "Unknown error",
      "detail": "Couldn't find schema for type: dealership"
    }
  ],
  "jsonapi": {
    "version": "1.0"
  }
}
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