Skip to content

Validation on Fields from Hooks #1191

Open
@thekevinbrown

Description

@thekevinbrown

Describe the bug
If a hook sets a value that doesn't exist on the entity, the code succeeds in execution, but the result is not what the developer expects.

From Slack: The code in BeforeCreateHook for SustainabilityAttribute was supposed to set { organization: { id: 'org_##########' } } but in my haste, I accidentally told it to set { organization_id: 'org_##########' } } (the field is named organization_id in the db). In order to debug it, I have to set breakpoints in your code to see what's happening since the error returned isn't really helpful. It would be nice if it gave us something like invalid field: organization_id on entity SustainabilityAttribute .

Expected behavior
In development, we should validate that the fields set by hooks are real fields. In production we should not do this check unless explicitly enabled as it will have performance implications.

Actual behavior
Code runs without error, result is not what developer expected.

Additional context
https://graphweaver.slack.com/archives/D0730MYM74Z/p1726103546839589?thread_ts=1723672001.215299&cid=D0730MYM74Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions