Skip to content

values proc validator runs at startup #801

Closed
@bradrobertson

Description

@bradrobertson

We've got a param validator that looks like this:

param :x, type: String, values: ->(){ SomeModel.pluck(:code) }

Where SomeModel is an ActiveRecord model. For some reason, this values proc is run at startup of our application (ie the moment the values declaration is made). In our test suite when we run a rake db:schema:load, this proc runs, but since the schema obviously doesn't exist yet at this point, the startup fails with ERROR: relation "some_models" does not exist.

At this point I assumed that proc was running the one time and storing the value, which would make it useless for us, but I've verified that it does indeed get called at runtime during a request as we're able to get the validation values to change with new rows in the db.

So I have to ask then, is there a reason this block runs at the moment that it's defined? It appears as if the code is verifying that the validator params are themselves valid, but I don't know the Grape source all that well.

Is this a bug? An intentional decision?

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