From 646a901af5427fb09bb8f19e827dd134cb4203b7 Mon Sep 17 00:00:00 2001 From: collerek Date: Thu, 6 Jan 2022 19:35:13 +0100 Subject: [PATCH] clean unused code --- .pre-commit-config.yaml | 2 +- ormar/queryset/actions/filter_action.py | 20 ------------------- ormar/relations/alias_manager.py | 1 - .../test_dates_with_timezone.py | 17 ++++++++-------- .../test_nested_reverse_relations.py | 4 ++-- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1a1cc4f..d720888 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 21.9b0 + rev: 21.12b0 hooks: - id: black exclude: docs_src diff --git a/ormar/queryset/actions/filter_action.py b/ormar/queryset/actions/filter_action.py index fcd7508..e393333 100644 --- a/ormar/queryset/actions/filter_action.py +++ b/ormar/queryset/actions/filter_action.py @@ -1,4 +1,3 @@ -import datetime from typing import Any, TYPE_CHECKING, Type import sqlalchemy @@ -137,8 +136,6 @@ class FilterAction(QueryAction): if isinstance(self.filter_value, ormar.Model): self.filter_value = self.filter_value.pk - # self._convert_dates_if_required() - op_attr = FILTER_OPERATORS[self.operator] if self.operator == "isnull": op_attr = "is_" if self.filter_value else "isnot" @@ -156,20 +153,3 @@ class FilterAction(QueryAction): if self.has_escaped_character: clause.modifiers["escape"] = "\\" return clause - - def _convert_dates_if_required(self) -> None: - """ - Converts dates, time and datetime to isoformat - """ - if isinstance( - self.filter_value, (datetime.date, datetime.time, datetime.datetime) - ): - self.filter_value = self.filter_value.isoformat() - - if isinstance(self.filter_value, (list, tuple, set)): - self.filter_value = [ - x.isoformat() - if isinstance(x, (datetime.date, datetime.time, datetime.datetime)) - else x - for x in self.filter_value - ] diff --git a/ormar/relations/alias_manager.py b/ormar/relations/alias_manager.py index 4f004db..c8bd1a6 100644 --- a/ormar/relations/alias_manager.py +++ b/ormar/relations/alias_manager.py @@ -79,7 +79,6 @@ class AliasManager: """ alias = f"{alias}_" if alias else "" aliased_fields = [f"{alias}{x}" for x in fields] if fields else [] - # TODO: check if normal fields still needed or only aliased one all_columns = ( table.columns if not fields diff --git a/tests/test_model_definition/test_dates_with_timezone.py b/tests/test_model_definition/test_dates_with_timezone.py index 58b1136..afb6fbd 100644 --- a/tests/test_model_definition/test_dates_with_timezone.py +++ b/tests/test_model_definition/test_dates_with_timezone.py @@ -130,13 +130,14 @@ async def test_query_with_time_in_filter(): @pytest.mark.asyncio async def test_filtering_by_timezone_with_timedelta(): - now_utc = datetime.now(timezone.utc) - object = MyModel(created_at=now_utc) - await object.save() + async with database: + now_utc = datetime.now(timezone.utc) + object = MyModel(created_at=now_utc) + await object.save() - one_hour_ago = datetime.now(timezone.utc) - timedelta(hours=1) - created_since_one_hour_ago = await MyModel.objects.filter( - created_at__gte=one_hour_ago - ).all() + one_hour_ago = datetime.now(timezone.utc) - timedelta(hours=1) + created_since_one_hour_ago = await MyModel.objects.filter( + created_at__gte=one_hour_ago + ).all() - assert len(created_since_one_hour_ago) == 1 + assert len(created_since_one_hour_ago) == 1 diff --git a/tests/test_queries/test_nested_reverse_relations.py b/tests/test_queries/test_nested_reverse_relations.py index bbe2091..2f28362 100644 --- a/tests/test_queries/test_nested_reverse_relations.py +++ b/tests/test_queries/test_nested_reverse_relations.py @@ -48,7 +48,7 @@ class DataSourceTableColumn(ormar.Model): @pytest.fixture(autouse=True, scope="module") -def create_test_database(): +def create_test_database(): # pragma: no cover engine = sqlalchemy.create_engine(DATABASE_URL) metadata.drop_all(engine) metadata.create_all(engine) @@ -61,7 +61,7 @@ def create_test_database(): reason="wait for fix for sqlite in encode/databases", ) @pytest.mark.asyncio -async def test_double_nested_reverse_relation(): +async def test_double_nested_reverse_relation(): # pragma: no cover async with database: data_source = await DataSource(name="local").save() test_tables = [