Hi,I have a Field of the following format:Field('meeting_time', 'datetime',requires=(IS_NOT_EMPTY(), IS_EXPR(lambda v: T('The meeting time cannot exceed one year from now') if(v > get_years_ahead_string(1)) else None), IS_DATETIME()))
The Field used to work properly, but today I noticed that if the IS_EXPR() requirement fails, the subsequent IS_DATETIME() requirement returns an error, and the program stops. The expected behavior is that the UI simply displays the error message provided by IS_EXPR(). The exact error is copied below:File "/py4web/py4web/utils/form.py", line 95, in make
_value=field.formatter("" if value is None else value),
File "/py4web/venv/lib/python3.10/site-packages/pydal/objects.py", line 2449, in formatter
value = item.formatter(value)
File "/py4web/venv/lib/python3.10/site-packages/pydal/validators.py", line 3962, in formatter
year = value.year
AttributeError: 'str' object has no attribute 'year'As shown, the error is in the IS_DATETIME formatter. I noticed a commit was recently made to pydal titled "version 20260216.1, fixes formatter for numbers and dates". To err on the side of caution, I updated pydal. But the issue persists. I plan to create a minimal example and send it over. In the meantime, please let me know if you have any insights into what the cause could be.Thank you!- ali
Dave,Thank you for your input.I have faced the issue with SQLite and AWS's RDS MySQL.
You are right, v is the meeting time. The datetime communicated over the network is of the type string. (An example is 2026-03-02T13:12:01 retrieved from request.POST). That is why I compared v with a stringified datatime. (And as I said before, everything was fine until recently.)
Here is a minimal example to reproduce the issue. Define:db.define_table('test',Field('name'),Field('meeting_time', 'datetime', requires=(IS_EXPR(lambda v: T('The meeting time cannot be set beyond 2026.') if(v > "2026-12-31T23:59:59") else None), IS_DATETIME())))Try adding values to it using a simple endpoint coded as below:@action('test', method=['GET', 'POST'])@action.uses('generic.html', db, auth, notification_count_injector)def test():test_form = Form(db.test, csrf_session=session, formstyle=FormStyleBulma)return dict(test_form=test_form)When submitting the form, if you add a meeting time before 2026, everything works fine. However, if a value after 2026 is entered, the program stops with the error mentioned above. The expected behavior is simply for the UI to display the error message inside IS_EXPR.Please do not hesitate to let me know if any additional information is needed.Thank!- ali
--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/0d1e76b8-91fb-42a2-927e-b8521e0b4ee5n%40googlegroups.com.