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

Bug doing put in model whit unique field (version 2.4.5) #428

Closed
josejachuf opened this issue Apr 6, 2022 · 3 comments
Closed

Bug doing put in model whit unique field (version 2.4.5) #428

josejachuf opened this issue Apr 6, 2022 · 3 comments

Comments

@josejachuf
Copy link

josejachuf commented Apr 6, 2022

I have a model with a unique field, if I make a put (using Emmett-REST) I get an error in which you do not be valid and forces me to change name value


class MyModel(Model):
    tablename = "my_model"

    name = Field.string(length=100, unique=True)
    start = Field.date()
    end = Field.date()
    
    validation = {
        'name': {'presence': True},
        'start': {'format': '%d/%m/%Y'},
        'end': {'format': '%d/%m/%Y'},       
    }

This fails with these versions:

emmett 2.4.5
emmett-rest 1.4

and works fine whit:

emmett 2.3.1
emmett-rest 1.2.0

@josejachuf
Copy link
Author

Error also with

emmett 2.4.5
emmett 2.3.1

@josejachuf josejachuf changed the title Bug doing put in model whit unique field (in new versions) Bug doing put in model whit unique field (version 2.4.5) Apr 6, 2022
@gi0baro
Copy link
Member

gi0baro commented Apr 10, 2022

@josejachuf unfortunately, the unique validator is still based on the pretty-old pyDAL implementation. I already planned some changes for 2.5 in regard of models validations, but with 2.4 there's no easy way support this.

In order to solve your issue in the meantime you have two options:

i) rely on index constraint only, dropping the unique parameter from you field and implementing the validation logic manually on the "controller" side
ii) hack the validation in your REST endpoint (I would say in a before_update callback) doing what forms do, eg:

@your_rest_module.before_update
def _fix_unique_validator(row, params):
    current._dbvalidation_record_id_ = row.id

I gonna keep this open until I write down a proper feature change for 2.5

@gi0baro
Copy link
Member

gi0baro commented May 25, 2022

I'm closing this in favour of emmett-framework/firestorm#2

@gi0baro gi0baro closed this as completed May 25, 2022
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

2 participants