Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fixed
^^^^^
- Rename pypika to pypika_tortoise for fixing package name conflict (#1829)
- Concurrent connection pool initialization (#1825)
- `_get_dialects`: support properties (#1859)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more explicit to use the issue title: _get_dialects not working for properties


Changed
^^^^^^^
Expand Down
10 changes: 8 additions & 2 deletions tests/test_early_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ async def test_early_init(self):
"description": "The Event NAME",
"docstring": "The Event NAME\nIt's pretty important",
"constraints": {"max_length": 255},
"db_field_types": {"": "VARCHAR(255)"},
"db_field_types": {
"": "VARCHAR(255)",
"oracle": "NVARCHAR2(255)",
},
},
{
"name": "created_at",
Expand Down Expand Up @@ -252,7 +255,10 @@ async def test_early_init(self):
"name": "name",
"field_type": "CharField",
"db_column": "name",
"db_field_types": {"": "VARCHAR(255)"},
"db_field_types": {
"": "VARCHAR(255)",
"oracle": "NVARCHAR2(255)",
},
"python_type": "str",
"generated": False,
"nullable": False,
Expand Down
65 changes: 52 additions & 13 deletions tests/utils/test_describe_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def test_describe_model_straight(self):
"name": "chars",
"field_type": "CharField",
"db_column": "chars",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": False,
Expand All @@ -186,7 +189,10 @@ def test_describe_model_straight(self):
"name": "blip",
"field_type": "CharField",
"db_column": "blip",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": False,
Expand All @@ -201,7 +207,10 @@ def test_describe_model_straight(self):
"name": "nullable",
"field_type": "CharField",
"db_column": "nullable",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": True,
Expand Down Expand Up @@ -391,7 +400,10 @@ def test_describe_model_straight_native(self):
"name": "chars",
"field_type": fields.CharField,
"db_column": "chars",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": False,
Expand All @@ -406,7 +418,10 @@ def test_describe_model_straight_native(self):
"name": "blip",
"field_type": fields.CharField,
"db_column": "blip",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": False,
Expand All @@ -421,7 +436,10 @@ def test_describe_model_straight_native(self):
"name": "nullable",
"field_type": fields.CharField,
"db_column": "nullable",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": True,
Expand Down Expand Up @@ -611,7 +629,10 @@ def test_describe_model_source(self):
"name": "chars",
"field_type": "CharField",
"db_column": "some_chars_table",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": False,
Expand All @@ -626,7 +647,10 @@ def test_describe_model_source(self):
"name": "blip",
"field_type": "CharField",
"db_column": "da_blip",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": False,
Expand All @@ -641,7 +665,10 @@ def test_describe_model_source(self):
"name": "nullable",
"field_type": "CharField",
"db_column": "some_nullable",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": "str",
"generated": False,
"nullable": True,
Expand Down Expand Up @@ -831,7 +858,10 @@ def test_describe_model_source_native(self):
"name": "chars",
"field_type": fields.CharField,
"db_column": "some_chars_table",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": False,
Expand All @@ -846,7 +876,10 @@ def test_describe_model_source_native(self):
"name": "blip",
"field_type": fields.CharField,
"db_column": "da_blip",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": False,
Expand All @@ -861,7 +894,10 @@ def test_describe_model_source_native(self):
"name": "nullable",
"field_type": fields.CharField,
"db_column": "some_nullable",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"python_type": str,
"generated": False,
"nullable": True,
Expand Down Expand Up @@ -1180,7 +1216,10 @@ def test_describe_model_uuidpk_relatednull(self):
"data_fields": [
{
"db_column": "name",
"db_field_types": {"": "VARCHAR(50)"},
"db_field_types": {
"": "VARCHAR(50)",
"oracle": "NVARCHAR2(50)",
},
"default": None,
"description": None,
"docstring": None,
Expand Down
24 changes: 17 additions & 7 deletions tortoise/fields/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import sys
import warnings
from collections.abc import Callable
Expand Down Expand Up @@ -297,16 +298,25 @@ def constraints(self) -> dict:
def _get_dialects(self) -> dict[str, dict]:
ret = {}
for dialect in [key for key in dir(self) if key.startswith("_db_")]:
item = {}
cls = getattr(self, dialect)
try:
cls = cls(self)
cls_instance = cls(self)
d = itertools.chain(
# dialect class attributes:
cls.__dict__.items(),
# dialect instance attributes:
cls_instance.__dict__.items(),
# dialect instance properties:
(
(prop, getattr(cls_instance, prop))
for prop in (
func for func in dir(cls) if isinstance(getattr(cls, func), property)
)
),
)
except TypeError:
pass
for key, val in cls.__dict__.items():
if not key.startswith("_"):
item[key] = val
ret[dialect[4:]] = item
d = cls.__dict__.items()
ret[dialect[4:]] = {key: val for key, val in d if not key.startswith("_")}
return ret

def get_db_field_types(self) -> Optional[dict[str, str]]:
Expand Down
Loading