Issue #11 new

Silent failure if fieldset has only one field

sanderkrause
created an issue

Hi there!

It's my first time actually reporting a bug, so bear with me if I make a mistake or omit something. Just ask if you need more information :)

I've been having issues when defining a fieldset with only one field. There seems to be a silent error, no Exception thrown, nothing. But, if I define a fieldset with only one field in it, I cannot use it in a template.

Example code:

fieldsets = (

('first', {'fields': ('one', 'two', 'three'), 'legend': ''}),

('second', {'fields': ('four', 'five', 'six'), 'legend': ''}),

('third', {'fields': ('single'), 'legend': ''})

)

While testing with a form (similar to the above code, but with different field names of course) I could only get the second fieldset to actually work. Only when I removed the last one (with the single field) I could use both other fieldsets. I tried iterating the fieldsets and explicitly calling fieldsets. I'm not aware of any documentation that describes issues with this, so I think it's a bug.

FYI: I don't use the legends or names in my template code, just the fieldsets as collection of form fields.

Comments (2)

  1. Carl Meyer repo owner

    "fields" needs to be an iterable, either a list or tuple. In the case of your third fieldset, it isn't. This is a common Python gotcha: it's actually the commas, not the parens, that make a tuple a tuple, parens are just for grouping clarity. A length-one tuple requires a trailing comma. Use "('single',)" in place of "('single')" and it should work fine. Actually I recommend just using lists instead, where this gotcha doesn't apply: "['single']" will work.

    That said, the silent failure you describe isn't the ideal failure mode in this case; I need to make it fail faster and with a clear error.

  2. Anonymous

    Hey, thanks for the clarification. I do feel a bit newbish now, but that's okay.

    I reckon you probably haven't had much time to extend the current documentation with tutorials and such, but I'm glad that it's at least up-to-date.

    Thanks again, I'll try and make my little project work :)

  3. Log in to comment