Describe the bug
When the DB contains models with at least one field of type tortoise.contrib.postgres.fields.TSVectorField, the instance cannot be fetched by the ORM producing the following exception:
File "C:\_PROG_\WPy64-31020\python-3.10.2.amd64\lib\site-packages\tortoise\queryset.py", line 1006, in _execute
instance_list = await self._db.executor_class(
File "C:\_PROG_\WPy64-31020\python-3.10.2.amd64\lib\site-packages\tortoise\backends\base\executor.py", line 138, in execute_select
instance: "Model" = self.model._init_from_db(
File "C:\_PROG_\WPy64-31020\python-3.10.2.amd64\lib\site-packages\tortoise\models.py", line 738, in _init_from_db
None if value is None else field.field_type(value),
TypeError: 'NoneType' object is not callable
The instance is present in the DB with the tsvector field as expected:
To Reproduce
Create a Model with a Postgres tsvector field, e.g.
from tortoise import fields
from tortoise.models import Model
from tortoise.contrib.postgres.indexes import GinIndex
from tortoise.contrib.postgres.fields import TSVectorField
class EventPartner(Model):
id = fields.IntField(pk=True)
name = fields.CharField(max_length=256,)
logo = fields.TextField(default='')
tsearch = TSVectorField(null=True, default=None) # the TSVector field for full-text search
class Meta:
ordering = ['name']
indexes = [GinIndex(fields={'tsearch'})]
2. Init the ORM and generate the schema as usual:
```python
await Tortoise.init(config=TORTOISE_CONFIG)
await Tortoise.generate_schemas()
At this stage, there is no problem -- the DB is created as expected.
[Optional: add some data]
await EventPartner.create(name='partner')
Now try fetching the first (or any) instance of the model:
You will get the error: `TypeError: 'NoneType' object is not callable`.
**Expected behavior**
I'd expect the ORM to fetch instances in the usual manner. In the latter example, the first added `EventPartner` object ought to be retrieved.
**Additional context**
Python = 3.10.2
Python package versions:
- asyncpg==0.26.0
- python-rapidjson==1.9
- tortoise-orm==0.19.2
PostgreSQL DB / server version 14.2
Describe the bug When the DB contains models with at least one field of type
tortoise.contrib.postgres.fields.TSVectorField
, the instance cannot be fetched by the ORM producing the following exception:The instance is present in the DB with the tsvector field as expected:![image](https://user-images.githubusercontent.com/5337394/199645041-f1cb7795-f84f-40ac-99fe-2bdfbe346f8b.png)
To Reproduce
class EventPartner(Model): id = fields.IntField(pk=True) name = fields.CharField(max_length=256,) logo = fields.TextField(default='') tsearch = TSVectorField(null=True, default=None) # the TSVector field for full-text search
At this stage, there is no problem -- the DB is created as expected.
[Optional: add some data]
Now try fetching the first (or any) instance of the model:
or like this
await db.EventPartner.all()
or with any query
await db.EventPartner.get_or_none(name__iexact='partner')