Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer validation when setting a value to an EmbeddedField #98

Open
avrahamshukron opened this issue Oct 10, 2017 · 0 comments
Open

Defer validation when setting a value to an EmbeddedField #98

avrahamshukron opened this issue Oct 10, 2017 · 0 comments

Comments

@avrahamshukron
Copy link
Contributor

Consider the following model:

class DatabaseConfig(Base):
    base_url = fields.StringField(required=True)
    db_name = fields.StringField(required=True)

class Config(Base):
    db = EmbeddedField(DatabaseConfig, required=True)

I can create an empty instance of Config, that I can populate with values until validation is required:

conf = Config()
db = DatabaseConfig()

At this point I can assign values to all the fields of db, But I cannot assign db itself to the corresponding field in config:

In [12]: conf.db = db
ValidationError: ("Error for field 'db'.", ValidationError("Error for field 'base_url'.", ValidationError('Field is required!',)))

While I understand why this is happening (fields validates values on assignment in __set__, and in the case of EmbeddedField this means calling validate on the embedded field), this is very annoying since I have to pre-initialize all the embedded fields beforehand.

I think it would be better to defer the validation of EmbeddedField until validate is called on the containing model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant