Skip to content

Re-rendering a form with validation errors results in blank fields #18

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

Closed
georgebrock opened this issue Feb 28, 2018 · 4 comments
Closed
Labels

Comments

@georgebrock
Copy link

When a form using a composite type widget is used with a generic form view (e.g. django.views.generic.UpdateView, or from the Django admin site), and the form has validation errors, the widgets that make up the composite type will be rendered without their values.

The issue seems to be that the CompositeTypeWidget.render method uses getattr(value, subname, None) to retrieve the values for the individual fields. This fails because when we're rendering the form with validation errors value is a dict, and not an instance of a subclass of CompositeType (as it is when we're rendering the form without errors).

@danni danni added the bug label Mar 1, 2018
@danni
Copy link
Owner

danni commented Mar 1, 2018

Hi George, are you able to supply a test case for this issue? I have not had this issue and I'm wondering if there's something different in the way that you're using it.

@georgebrock
Copy link
Author

Hi @danni. Thanks for making such a useful addition to Django, and for the quick reply on the issue!

I've put together a minimal Django app that demonstrates the issue: https://github.com/georgebrock/django-postgres-composite-types-issue-18

I also tried to add a test to this project's test suite, but I had trouble getting the suite to run. The issues I was hitting there seemed to be related to Django initialisation, so it's possible this is a Django 2.0 compatibility thing.

mx-moth pushed a commit to mx-moth/django-postgres-composite-types that referenced this issue Mar 6, 2018
Previously the submitted value for a composite field was lost if the
form had a validation error.

Fixes danni#18
@georgebrock
Copy link
Author

Thanks for this!

@mx-moth
Copy link
Collaborator

mx-moth commented Mar 7, 2018

The fixes for this issue and #17, have been released in v0.4.1 on PyPI.

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

No branches or pull requests

3 participants