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

Validate that the ID field exists, but don't load it #254

Open
multimeric opened this issue Sep 17, 2019 · 2 comments
Open

Validate that the ID field exists, but don't load it #254

multimeric opened this issue Sep 17, 2019 · 2 comments

Comments

@multimeric
Copy link

Following on from discussion here: json-api/json-api#1427.

Basically, it makes sense for JSON API servers to validate that there is an ID in all data it deals with, BUT there are situations where you don't want to have to see this ID after you load some data.

For instance, I have an example where my server returns a dictionary that corresponds to the keyword arguments to plotly.plot(), but it won't accept an ID field in the kwargs.

My current hack is this:

class EphemeralSchema(Schema):
    id = f.String(dump_only=True)

data = EphemeralSchema(unknown=EXCLUDE).load(response.json)

However, this means I have to use unknown=EXCLUDE, which I don't actually want to do (I want to include arbitrary kwargs). I also can't use exclude=['id'], because that will trigger json-api's schema validation.

What is the best solution here? I'm happy to write a PR, but I need a little guidance on how to best implement this.

@olinger
Copy link

olinger commented Feb 19, 2020

@TMiguelT Did you ever figure out a way to do this? I need to do something similar and can't figure out a way besides unknown=EXCLUDE (which I don't want to do).

@multimeric
Copy link
Author

No, it looks like I'm still using unknown=EXCLUDE in the code that uses this, sadly.

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