Skip to content

Is "Simplifying Ecto schema fields validation" really an improvement? #2

@RudolfMan

Description

@RudolfMan

First of all, thank you for this work! I really appreciate it!

I wanted to open a discussion regarding "Simplifying Ecto schema fields validation".

I've seen developers, when learned about Ecto schema reflection, start use it in changeset function just like shown in the refactoring example.

I'd argue it's a bad practice that potentially opens up security issues akin to what we have seen in Rails community prior to the introduction of StrongParameters.

And in real world a better practice, IMO, would be to explicitly declare separate lists for permitted_fields and required_fields. Either inline or in a variable or a module attribute, the point is to be explicit about fields.

Moreover, different actions might require different set of permitted_fields and required_field. Which might lead us to create different changeset functions, like: create_changeset that would allow and require more fields, while for update_changeset it could be only a subset of fields required or even allowed. But that's slightly tangental, though related.

Surely one could oppose saying that the developer must know what they are doing, instead of blindly copying the pattern from the internet. But these sort of "lists of refactorings" just like "anti-patterns" might looks like a "blessed way", so we gotta be careful 🙂

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