Skip to content

Numeric field handles TypeError - #936

Merged
azmeuk merged 3 commits into
pallets-eco:mainfrom
alanhamlett:master
Oct 19, 2026
Merged

azmeuk merged 3 commits into
pallets-eco:mainfrom
alanhamlett:master

Conversation

@alanhamlett

@alanhamlett alanhamlett commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes this traceback that I received using v3.2.2 in production:

Traceback (most recent call last):
  File "/opt/wakatime/current/wakatime/api_v1.py", line 2891, in consume_heartbeat_validate
    form = HeartbeatForm.from_json(data)
  File "/opt/wakatime/current/.venv/src/wtforms-json/wtforms_json/__init__.py", line 236, in from_json
    form = cls(
        formdata=MultiDict(
    ...<6 lines>...
        **kwargs
    )
  File "/opt/wakatime/current/.venv/lib/python3.14/site-packages/wtforms/form.py", line 209, in __call__
    return type.__call__(cls, *args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/wakatime/current/.venv/lib/python3.14/site-packages/wtforms/form.py", line 287, in __init__
    self.process(formdata, obj, data=data, **kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/wakatime/current/.venv/lib/python3.14/site-packages/wtforms/form.py", line 128, in process
    field.process(formdata, data, extra_filters=field_extra_filters)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/wakatime/current/.venv/src/wtforms-json/wtforms_json/__init__.py", line 192, in process
    func(self, formdata, data=data, **kwargs)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/wakatime/current/.venv/lib/python3.14/site-packages/wtforms/fields/core.py", line 320, in process
    self.process_formdata(self.raw_data)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/opt/wakatime/current/.venv/lib/python3.14/site-packages/wtforms/fields/numeric.py", line 165, in process_formdata
    self.data = decimal.Decimal(valuelist[0])
                ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
TypeError: conversion from dict to Decimal is not supported

@azmeuk

azmeuk commented Oct 19, 2026

Copy link
Copy Markdown
Member

Related to #198

The test you wrote, that is passing a dict in formdata, is not actually part of the wtforms contract. But that contract is not clearly defined either, and it is cheap enough to catch TypeErrors at the same time ValueError are caught. I added the same behavior for the other fields.

@azmeuk
azmeuk merged commit 46f626e into pallets-eco:main Oct 19, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants