Skip to content

ReferenceChecker don't get passed in a propper context #192

Open
@smyrman

Description

@smyrman

Code:

_, err = rsc.Get(context.TODO(), id)

The ReferenceChecker does not get passed in a request-scoped context (or any context for that matter), which means that any hooks that might run OnGet / OnGot for the resource in question don't get passed the relevant request context.

use-cases

There are many good use-cases for wanting to access the correct context in a hook.

One use-case, is permission handling, when it's reasonable to assume that the context may contain some user or permission related information.

Fix: pass in context to FieldValidator

The obvious fix may be to change the shema.FieldValidator interface to accept a context to be passed to the validator function. This is possile to do as a backwards-compatible change as well, as one could add a new interface, schema.CtxFieldValidator or so, to take precedence over schema.FieldValidaotor in type checks, but not sure the backwards-compatible path here is worth it before the v1.0 release.

There may be other changes that could be done to pass along the right context that isn't yet clear to me, but having the opurtunity to pass in context to a FieldValidator, probably makes senes anyway...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions