Skip to content

Conversation

@Callum027
Copy link
Collaborator

  • Fix parsing Python 3.10+ type hints when encoding search filters.
  • Fix parsing Python 3.10+ type hints when decoding record values.
  • Add missing release note for fixing parsing Python 3.10+ type hints when evaluating model refs.

@Callum027
Copy link
Collaborator Author

Callum027 commented Dec 14, 2025

Appears to be a bug caused by this.

  File "...", line 382, in _add_term_discounts
    project_term_discounts = self.odoo_client.term_discounts.search(
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../openstack_odooclient/base/record_manager/base.py", line 548, in search
    ids: list[int] = self._env.search(
                     ^^^^^^^^^^^^^^^^^
  File ".../odoorpc/models.py", line 59, in rpc_method
    result = cls._odoo.execute_kw(cls._name, method, args, kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../odoorpc/odoo.py", line 524, in execute_kw
    data = self.json(
           ^^^^^^^^^^
  File ".../odoorpc/odoo.py", line 271, in json
    data = self._connector.proxy_json(url, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../odoorpc/rpc/jsonrpclib.py", line 110, in __call__
    data_json = json.dumps(data)
                ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable

EDIT: This is happening because type_hint_origin is being used here instead of type_hint.

This bug has existed since the start, but recent changes in clients have caused this particular code path to be used for a date | None type attribute. Will fix as part of this PR.

EDIT 2: Fix tested and commited.

>>> encode_value(list[datetime], [datetime.now()])
['2025-12-15 14:29:46']
>>> encode_value(list[Union[datetime, date]], [datetime.now(), date.today()])
['2025-12-15 14:30:01', '2025-12-15']
>>> encode_value(int, 123)
123
>>> encode_value(float, 123)
123
>>> encode_value(date, datetime.today())
'2025-12-15'
>>> encode_value(date, date.today())
'2025-12-15'
>>> encode_value(datetime, datetime.now())
'2025-12-15 14:31:05'
>>> encode_value(datetime | None, datetime.now())
'2025-12-15 14:31:14'
>>> encode_value(Union[datetime, None], datetime.now())
'2025-12-15 14:31:25'
>>> encode_value(datetime | None, None)
>>> encode_value(Union[datetime, None], None)
>>> encode_value(Optional[datetime], datetime.now())
'2025-12-15 14:32:08'
>>> encode_value(Optional[datetime], None)
>>> encode_value(list[datetime], [datetime.now()])
['2025-12-15 14:32:23']
>>> encode_value(list[Union[datetime, date]], [datetime.now(), date.today()])
['2025-12-15 14:32:27', '2025-12-15']

* Fix parsing Python 3.10+ type hints when encoding search filters.
* Fix parsing Python 3.10+ type hints when decoding record values.
* Add missing release note for fixing parsing Python 3.10+ type hints when evaluating model refs.
@Callum027 Callum027 marked this pull request as ready for review December 15, 2025 18:11
@adrianjarvis adrianjarvis merged commit 57344be into main Dec 15, 2025
6 checks passed
@Callum027 Callum027 deleted the callum/type-fixes-2 branch December 15, 2025 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants