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
TypeError: Boolean value of this clause is not defined #195
Comments
@aminalaee and thanks for library :) I hope you can help anyhow with my issue. File with models in txt |
Hey @xnuinside , Thank you, |
@aminalaee tried upload several times )) not sure why it's not loaded, one more time |
@aminalaee I will try today to experiment & remove fields till I find that exactly cause a problem, but if you will have ideas to make this investigation more quick :) I will appreciate |
I'm guessing that might be the server_default of Boolean field which I haven't tested, but it would be quicker if you can provide a minimal example to produce this. |
@aminalaee problem not in boolean field, so everything works ok if remove DateTime fields:
looks like they cause an issue |
and if check traceback you can see |
problem in 'default=func.now()' & 'onupdate=func.now()' if not use 'func.now()' everything is ok |
Ok great, that's a good start, feel free to create a PR for it or I'll have a look later 👍 |
@aminalaee I will close the issue, I just recognized, that in python 'default' not 'server_default' somebody put func.now() and this is the reason of issue, if change it to python datetime - everything ok |
Hello I have the same issue as @xnuinside I didn't quite get the solution but it seems to me that my models using func.now() are correct. |
@StorkST |
Hi @aminalaee Sure, here is my code. I hope this is good for you as an example. I think you might need to create the database with the simple So when I try to create a new User on the interface I get the error "Boolean value of this clause is not defined". main.py file runned with
|
@StorkST func.now() cannot be used in ‘default’ arg. Because it is DB function. default - for Python code that executes before send request to DB. Change func.now() to Python datetime.now() or use it in server_default |
Yeah As far as I remember this was expected, the default should be populated in the create form, and in the case of func.now() there's no way to set that value upfront. Switching to server_default works around this. P.S. if you think you can improve this, contributions are welcome. |
I believe it would be more natural to exclude the func.now() Datetime column from the form. class UserAdmin(ModelView, model=User):
form_excluded_columns = [ User.creationDate, User.updateDate ] Because using It would be convenient if the datetime column is automatically excluded when func_now() is used by including in form_excluded_columns. Thanks you. |
Hmm, that might be one solution. But maybe we should exclude any columns with |
As far as I test, |
I think my previous comment was not very clear. But I think modifying the behaviour based on |
Agreed with you. Thank you for your kindness :) |
Checklist
master
.Describe the bug
Traceback during open 'Create' page (url for example): http://127.0.0.1:8000/admin/user/create
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/starlette/templating.py", line 37, in init
content = template.render(context)
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqladmin/templates/create.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqladmin/templates/layout.html", line 1, in top-level template code
{% extends "base.html" %}
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqladmin/templates/base.html", line 15, in top-level template code
{% block body %}
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqladmin/templates/layout.html", line 49, in block 'body'
{% block content %} {% endblock %}
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqladmin/templates/create.html", line 18, in block 'content'
{{ field() }}
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/wtforms/fields/core.py", line 172, in call
return self.meta.render_field(self, kwargs)
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/wtforms/meta.py", line 64, in render_field
return field.widget(field, **render_kw)
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/wtforms/widgets/core.py", line 174, in call
kwargs["value"] = field._value()
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/wtforms/fields/datetime.py", line 36, in _value
return self.data and self.data.strftime(self.format[0]) or ""
File "/Users/iuliia_volkova2/Library/Caches/pypoetry/virtualenvs/admin-panel-service-Ji2bEy0B-py3.7/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 582, in bool
raise TypeError("Boolean value of this clause is not defined")
TypeError: Boolean value of this clause is not defined
Steps to reproduce the bug
I think something in model cause in issue - I send the sample
Also we use async SQLAlchemy engine. I will be glad if you will do some input where to dig or what can be a reason of the problem.
Expected behavior
Create form open correctly without issues.
Actual behavior
Impossible to open Create form
Debugging material
No response
Environment
SQLAdmin == 0.1.9
SQLAlchemy == 1.4.37
Additional context
No response
The text was updated successfully, but these errors were encountered: