Skip to content
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

Segmentation fault when SelectField choices is a list. #464

Closed
backwardspy opened this issue Feb 4, 2019 · 3 comments
Closed

Segmentation fault when SelectField choices is a list. #464

backwardspy opened this issue Feb 4, 2019 · 3 comments

Comments

@backwardspy
Copy link

backwardspy commented Feb 4, 2019

Project dependencies:

$ cat Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
flask = "*"
jinja2 = "*"
wtforms = "*"
flask-wtf = "*"
requests = "*"

[requires]
python_version = "3.6"

The SelectField in question:

option = SelectField(label='Option', choices=["a", "b", "c"])

Running the server then hitting the page in my browser:

$ flask run
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
'flask run' terminated by signal SIGSEGV (Address boundary error)

Changing the choices to the correct format (list of tuples) fixes the error.
I ran through the code in GDB but it's not clear where exactly the segfault occurs. It seems to appear somewhere amongst Jinja2 and/or WTForms.

Is this directly related to WTForms, or should I open this issue on Flask-WTF/Jinja2 instead?
If the former, is it worth placing a type check on this field to prevent the list getting through to the templating engine?

@ftm
Copy link
Contributor

ftm commented Feb 11, 2019

I can't seem to reproduce this exact error when using just WTForms, which makes me think that it might be coming from a different dependency. However as you can see from the message generated and from the docs, this is not how this field is meant to be used.

>>> from wtforms import Form, SelectField
>>> class OptionForm(Form):
...     options = SelectField(label="Option", choices=["a", "b", "c"])
... 
>>> form = OptionForm(options="a")
>>> form.options.data
'a'
>>> form.validate()
False
>>> form.errors
{'options': ['not enough values to unpack (expected 2, got 1)']}

@backwardspy
Copy link
Author

Fair enough. I expect you're right; it's probably some obscure intersection of the dependencies in this project. Thank you for taking the time to investigate this.

@shiki009
Copy link

We are also seeing this with an input where choices is a list of lists(3):

[['ashkj', 'sadfsdf', 'asdfsad'], ['adsfasfd', 'asdfsdf', 'asdfasd']]

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

No branches or pull requests

3 participants