Skip to content

In Validateable Trait - constrained properties is cached, which means it doesn't always reflect the constraints used by validate method #12362

@boardbloke

Description

@boardbloke

Issue description

This is a bit esoteric, but regardless...

Because the Validateable trait caches the constraints in constraintsMapInternal, the constraints you get when you call Validateable.getConstraintsMap() are not always the same as those that are in effect when you call Validateable.validate()

I found this issue because I am using Validateable.getConstraintsMap() to check in a unit test what constraints have ben applied, and what properties those constraints have.

The test sets some config (which the constraints use) prior to the test running, and checking the configured constraints via Validateable.getConstraintsMap() is not working because a previous test causes the constraints to be cached. The result of calling Validateable.getConstraintsMap() therefore contains the constraints configured as they were in the previous test.

This does not happen if you use Validateable.validate - as that method calculated the constraints in effect on every call.

The solution I think is to either not cache the constraints in Validateable.getConstraintsMap(), so it works the same as Validateable.validate(), or provide a method in Validateable that can reset constraintsMapInternal - which would allow unit tests to reset the cache prior to changing config

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions