Skip to content

CRITICAL BUG in FormAlchemy v1.4.3: _sanitize_select_options() in helpers.py #52

@coredumperror

Description

@coredumperror

I can't even begin to imagine what this thing is supposed to be doing, but what it's actually doing is destroying long <select> lists.

Here's the code for the function:

def _sanitize_select_options(options):
    if isinstance(options, (list, tuple)):
        if _only_contains_leaves(options) and len(options) >= 2:
            return (options[1], options[0])
        else:
            return [_sanitize_select_options(option) for option in options]
    return options

Notice that if the options variable is a list of length >= 2, with elements which are not also lists (e.g. a list of several strings), it converts options into (options[1], options[0]).

Why in the world does it do this? This results in every list of 2+ options being incorrectly rendered into a <select>.

I'm no expert when it comes to recursive functions, but it appears that (besides destroying every option list) this function doesn't do anything. When I made what appeared to be the most sensible fix the remove the bug, I realized that the function stopped having any effect.

I'd suggest either removing _sanitize_select_options(), or re-writing it to do what it was originally intended to do, whatever that was. Until that time, though, FormAlchemy v1.4.3 is completely worthless. I was forced to downgrade to v1.4.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions