Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion ormar/decorators/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def pre_relation_remove(senders: Union[Type["Model"], List[Type["Model"]]]) -> C


def post_relation_remove(
senders: Union[Type["Model"], List[Type["Model"]]]
senders: Union[Type["Model"], List[Type["Model"]]],
) -> Callable:
"""
Connect given function to all senders for post_relation_remove signal.
Expand Down
2 changes: 1 addition & 1 deletion ormar/fields/model_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def validate(cls, **kwargs: Any) -> None:
:param kwargs: all params passed during construction
:type kwargs: Any
"""
max_length = kwargs.get("max_length", None)
max_length = kwargs.get("max_length", -1)
if max_length <= 0:
raise ModelDefinitionError(
"Parameter max_length is required for field String"
Expand Down
10 changes: 5 additions & 5 deletions ormar/fields/referential_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ReferentialAction(Enum):
that shall take place in such occurrences.
"""

CASCADE: str = "CASCADE"
RESTRICT: str = "RESTRICT"
SET_NULL: str = "SET NULL"
SET_DEFAULT: str = "SET DEFAULT"
DO_NOTHING: str = "NO ACTION"
CASCADE = "CASCADE"
RESTRICT = "RESTRICT"
SET_NULL = "SET NULL"
SET_DEFAULT = "SET DEFAULT"
DO_NOTHING = "NO ACTION"
6 changes: 3 additions & 3 deletions ormar/models/helpers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if TYPE_CHECKING: # pragma no cover
from ormar import Model
from ormar.fields import ForeignKeyField, ManyToManyField
from ormar.fields import BaseField, ForeignKeyField, ManyToManyField

alias_manager = AliasManager()

Expand Down Expand Up @@ -288,7 +288,7 @@ def register_through_shortcut_fields(model_field: "ManyToManyField") -> None:
setattr(model_field.to, through_name, RelationDescriptor(name=through_name))


def register_relation_in_alias_manager(field: "ForeignKeyField") -> None:
def register_relation_in_alias_manager(field: "BaseField") -> None:
"""
Registers the relation (and reverse relation) in alias manager.
The m2m relations require registration of through model between
Expand All @@ -309,7 +309,7 @@ def register_relation_in_alias_manager(field: "ForeignKeyField") -> None:
elif field.is_relation and not field.is_through:
if field.has_unresolved_forward_refs():
return
register_relation_on_build(field=field)
register_relation_on_build(field=cast("ForeignKeyField", field))


def verify_related_name_dont_duplicate(
Expand Down
7 changes: 4 additions & 3 deletions ormar/queryset/queries/query.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union, cast

import sqlalchemy
from sqlalchemy import Column, Select, Table, TextClause
from sqlalchemy.sql import Join
from sqlalchemy.sql.roles import FromClauseRole

import ormar # noqa I100
from ormar.models.helpers.models import group_related_list
Expand Down Expand Up @@ -148,11 +149,11 @@ def build_select_expression(self) -> sqlalchemy.sql.Select:
if self._pagination_query_required():
limit_qry, on_clause = self._build_pagination_condition()
self.select_from = sqlalchemy.sql.join(
self.select_from, limit_qry, on_clause
cast("FromClauseRole", self.select_from), limit_qry, on_clause
)

expr = sqlalchemy.sql.select(*self.columns)
expr = expr.select_from(self.select_from)
expr = expr.select_from(cast("FromClauseRole", self.select_from))

expr = self._apply_expression_modifiers(expr)

Expand Down
4 changes: 3 additions & 1 deletion ormar/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,9 @@ async def bulk_update( # noqa: CCR001
)
await asyncio.sleep(0)

pk_column = self.model_config.table.c.get(self.model.get_column_alias(pk_name))
pk_column: sqlalchemy.Column = self.model_config.table.c[
self.model.get_column_alias(pk_name)
]
pk_column_name = self.model.get_column_alias(pk_name)
table_columns = [c.name for c in self.model_config.table.c]
expr = self.table.update().where(
Expand Down
1 change: 1 addition & 0 deletions ormar/queryset/reverse_alias_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def _resolve_column_with_prefix(self, column_name: str, prefix: str) -> None:
:type prefix: str
"""
relation = self.reversed_aliases.get(prefix, None)
assert relation is not None, "Prefix not found in reversed aliases"
relation_str = self._prefixes.get(relation, None)
field = self._fields.get(relation, None)
if relation_str is None or field is None:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ormar

from tests.settings import create_config

base_ormar_config = create_config()


class Department(ormar.Model):
ormar_config = base_ormar_config.copy()

id: int = ormar.Integer(primary_key=True)
name: str = ormar.String(max_length=100)
Loading