Skip to content

InputRequired & DataRequired validators on same field #152

Description

@0xbart

Hi there, I hope one of you can help me with the strange following question.

First of all, I've create a Model with SQLAlchemy:
(Note that the BaseModel is my BaseModel with a UUID included.

class Company(BaseModel):
    reseller = Column(UUIDType(), ForeignKey('company.uuid'))
    name = Column(VARCHAR(500), unique=True, nullable=False)

The next step is to create the actual Form.

class CompanyForm(ModelForm):
    class Meta:
        model = Company

After that, I wanna debug what kind of validators there are active on the name column:

c = CompanyForm()
print(c.name.validators)

# [<wtforms.validators.InputRequired object at 0x1068455e0>, <wtforms.validators.DataRequired object at 0x106845640>, <wtforms.validators.Length object at 0x1067bc130>, <wtforms_alchemy.validators.Unique object at 0x1067bc550>]

The next step is to call the form in the Rest API incoming response with the data given to the object. But InputRequired / DataRequired always validate to False.

# When using -D (curl) the DataRequired() is successfully, but the InputRequired failed
➜  ~ curl -XPUT -d '{"name": "bart"}' -H 'Content-Type: application/json' http://localhost:5000/api/v1/company/

# When using -F the InputRequired is sucessfully, but the dataRequired failed.
➜  ~ curl -XPUT -F "name=bart" http://localhost:5000/api/v1/company/                                           

Removing the nullable=False will fixed this problem. Is there someone who can help me? :-)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions