danni / django-postgres-composite-types

Postgres composite types support for Django
BSD 3-Clause "New" or "Revised" License
51 stars 13 forks source link

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

Closed georgebrock closed 6 years ago

georgebrock commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.

georgebrock commented 6 years ago

Thanks for this!

mx-moth commented 6 years ago

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