Skip to content

Issue with the TSVector column/field #2204

@CubeBeveled

Description

@CubeBeveled

Describe the bug
I have a model with a TSVectorField and whenever i try to save a model to the table with the TSVectorField i get the following error. When i remove the TSVectorField column this does not happen.

  File "/home/beveledcube/Git/bevel-bot/Main-py/from_mongodb.py", line 88, in main
    await new_player.save()
  File "/home/beveledcube/Git/bevel-bot/Main-py/env/lib64/python3.14/site-packages/tortoise/models.py", line 1190, in save
    await executor.execute_insert(self)
  File "/home/beveledcube/Git/bevel-bot/Main-py/env/lib64/python3.14/site-packages/tortoise/backends/base/executor.py", line 309, in execute_insert
    await self._process_insert_result(instance, insert_result)
  File "/home/beveledcube/Git/bevel-bot/Main-py/env/lib64/python3.14/site-packages/tortoise/backends/asyncpg/executor.py", line 11, in _process_insert_result
    return await super()._process_insert_result(instance, results)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/beveledcube/Git/bevel-bot/Main-py/env/lib64/python3.14/site-packages/tortoise/backends/base_postgres/executor.py", line 108, in _process_insert_result
    setattr(instance, model_field, field_object.to_python_value(val))
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "/home/beveledcube/Git/bevel-bot/Main-py/env/lib64/python3.14/site-packages/tortoise/fields/base.py", line 323, in to_python_value
    if value is not None and not isinstance(value, self.field_type):
                                 ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

To Reproduce

  1. Make a model with a TSVector field
class Player(Model):
    username = CharField(max_length=16, primary_key=True)
    ...

    search = TSVectorField(
        source_fields=("username",),
        config="simple",
        weights=("A",),
        stored=True,
        null=True,
    )
  1. Try to save it
new_player = Player(
    username=msg.username,
    ...
)

await new_player.save()

Expected behavior
The model gets saved correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions