Closed josejachuf closed 2 years ago
I need to investigate this. @josejachuf gonna update you as soon as I reproduce this.
@josejachuf can't reproduce this with the User
module in bloggy example. I suppose this might be due to the belongs
relation.
Does logging form.params
and form.input_params
help?
Hi @gi0baro
it's into if form.accepted:
form.params:
<sdict {'email': 'jjachuf@gmail.com', 'first_name': 'Jose', 'last_name': 'Jachuf', 'cuit': '123', 'institucion': 'd7cd362c70c542f0bab580be5f1f9fdc'}>
form.input_params:
<sdict {'last_name': 'Jachuf', 'institucion': 'd7cd362c70c542f0bab580be5f1f9fdc', 'email': 'jjachuf@gmail.com', 'cuit': '123', 'first_name': 'Jose', '_csrf_token': 'd2f70067-315b-41a1-a0d6-1549510e1735'}>
then update cuit is null or empty in database. This it's with postgresql
Any change I make is not taken at the update. However it works fine when creating new records
@josejachuf do you have any before
or after
callbacks for save or update operations? I tested this locally with the model and route you provided and it works for me.
Hi @gi0baro
No, I don't use any callbacks. In your test, you use PK uuid?
I did this and works fine:
if form.accepted:
if 'id' in form.params:
_id = form.params.id
row = User.get(_id)
row.update_record(**form.params)
redirect(url('.ficha', params=dict(id=_id)))
return dict(form=form)
@josejachuf yup, tried also with uuid, works fine for me. I'm definitely missing something. Can you try adding a couple of prints like this:
if form.accepted:
print(form.record.changes)
print(form.record.validation_errors)
form.record.changes
<sdict {'cuit': ('4321', '3333'), 'updated_at': (datetime.datetime(2022, 5, 18, 12, 43, 52), DateTime(2022, 5, 18,
13, 4, 53, 413197, tzinfo=Timezone('UTC')))}>
Here's the problem: form.record.validation_errors
<sdict {'password': 'La contraseña debe contener entre 8 y 50 caracteres', 'email': 'Ingrese el Correo Electrónico'
}>
but, I do:
exclude_fields = []
if _id:
exclude_fields = ['password']
And the email is included in the form
@josejachuf this is actually quite hard. The issue here is actually in regards of the password validation, as in 2.4 forms use the save
method of models, and thus validates the entire record, not just the fields coming from the form. And this is also true for every operation made on models containing "password" fields.
I gonna need some time to understand how to solve this.
@josejachuf this should actually have been fixed in current master. Do you mind making a test?
@gi0baro , the patch works fine!
Thanks
Hi @gi0baro
[emmett: 2.4.9]
Give the following model for User:
And the form to create and update
From the form I can create a user useless, but when I edit it, the changes are not registered. It does not give error of any kind, neither in the console nor in the browser
In this way I have working on Emmett 2.3.1 (and Weppy). I can't try this in version 2.3.1 for the use of PK as UUID, but in another old project it works.