Skip to content

Commit

Permalink
fix: create index sql error. (#1202) (#1240)
Browse files Browse the repository at this point in the history
* fix: create index sql error. (#1202)

* fix: ci failed

* fix: ci failed

* test: fix test_index_safe
  • Loading branch information
long2ice committed Sep 3, 2022
1 parent 11a0c69 commit db9c36c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches-ignore:
- master
types: [ closed ]
jobs:
test:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Changelog
Added
^^^^^
- Added config_class option to pydantic model genator that allows the developer to customize the generated pydantic model's `Config` class. (#1048)
Fixed
^^^^^
- Fix create index sql error. (#1202)

0.19.2
------
Expand Down
4 changes: 2 additions & 2 deletions tests/schema/test_generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ async def test_index_safe(self):
`full_text` LONGTEXT NOT NULL,
`geometry` GEOMETRY NOT NULL
) CHARACTER SET utf8mb4;
CREATE FULLTEXT INDEX IF NOT EXISTS `idx_index_full_te_3caba4` ON `index` (`full_text`) WITH PARSER ngram;
CREATE SPATIAL INDEX IF NOT EXISTS `idx_index_geometr_0b4dfb` ON `index` (`geometry`);""",
CREATE FULLTEXT INDEX `idx_index_full_te_3caba4` ON `index` (`full_text`) WITH PARSER ngram;
CREATE SPATIAL INDEX `idx_index_geometr_0b4dfb` ON `index` (`geometry`);""",
)

async def test_index_unsafe(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/testmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import uuid
from decimal import Decimal
from enum import Enum, IntEnum
from typing import Union
from typing import List, Union

import pytz
from pydantic import Extra as PydanticExtra
Expand Down Expand Up @@ -868,7 +868,7 @@ class PydanticConfig:

@staticmethod
def camelize_var(var_name: str):
var_parts: list[str] = var_name.split("_")
var_parts: List[str] = var_name.split("_")
return var_parts[0] + "".join([part.title() for part in var_parts[1:]])

title = "My custom title"
Expand Down
2 changes: 1 addition & 1 deletion tortoise/contrib/pydantic/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def get_param(attr: str) -> Any:
annotations = get_annotations(cls)

# Note: First ones override next ones' attributes
pconfig_bases: list[Type] = [PydanticModel.Config]
pconfig_bases: List[Type] = [PydanticModel.Config]
# If default config class is specified, we add it as first item of bases
if default_config_class:
pconfig_bases.insert(0, default_config_class)
Expand Down
2 changes: 1 addition & 1 deletion tortoise/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Index:
INDEX_TYPE = ""
INDEX_CREATE_TEMPLATE = (
"CREATE{index_type}INDEX {exists}{index_name} ON {table_name} ({fields}){extra};"
"CREATE{index_type}INDEX {index_name} ON {table_name} ({fields}){extra};"
)

def __init__(
Expand Down
6 changes: 5 additions & 1 deletion tortoise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,11 @@ async def update_or_create(
defaults = {}
db = using_db or cls._choose_db(True)
async with in_transaction(connection_name=db.connection_name) as connection:
instance = await cls.select_for_update().using_db(connection).get_or_none(**kwargs)
instance = (
await cls.select_for_update()
.using_db(connection)
.get_or_none(**kwargs) # type:ignore
)
if instance:
await instance.update_from_dict(defaults).save(using_db=connection) # type:ignore
return instance, False
Expand Down

0 comments on commit db9c36c

Please sign in to comment.