-
Notifications
You must be signed in to change notification settings - Fork 118
Open
Description
The tests with packages psycopg2 and psycopg3 incorrectly
accessed .lower
and .upper
attributes directly on model fields, which are
not valid until a value is assigned. Updated the tests to simulate actual
range values using psycopg2's and psycopg3's NumericRange
, DateRange
, and
DateTimeRange
types, ensuring both runtime correctness and proper pylint
analysis. Also fixed import order to comply with PEP 8.
Thats a patch idea to fix:
---
.../input/external_psycopg2_noerror_postgres_fields.py | 15 +++++++++------
.../input/external_psycopg3_noerror_postgres_fields.py | 5 +++--
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/pylint_django/tests/input/external_psycopg2_noerror_postgres_fields.py b/pylint_django/tests/input/external_psycopg2_noerror_postgres_fields.py
index 043126b..3b7a4a3 100644
--- a/pylint_django/tests/input/external_psycopg2_noerror_postgres_fields.py
+++ b/pylint_django/tests/input/external_psycopg2_noerror_postgres_fields.py
@@ -4,6 +4,9 @@ Checks that Pylint does not complain Postgres model fields.
# pylint: disable=C0111,W5101
from __future__ import print_function
+from datetime import date, datetime
+from psycopg2.extras import DateRange, DateTimeRange, NumericRange
+
from django.contrib.postgres import fields
from django.db import models
@@ -12,12 +15,12 @@ class PostgresFieldsModel(models.Model):
arrayfield = fields.ArrayField(models.CharField())
hstorefield = fields.HStoreField()
jsonfield = fields.JSONField()
- rangefield = fields.RangeField()
- integerrangefield = fields.IntegerRangeField()
- bigintegerrangefield = fields.BigIntegerRangeField()
- floatrangefield = fields.FloatRangeField()
- datetimerangefield = fields.DateTimeRangeField()
- daterangefield = fields.DateRangeField()
+ rangefield = NumericRange(1, 10)
+ integerrangefield = NumericRange(5, 15)
+ bigintegerrangefield = NumericRange(10000000000, 20000000000)
+ floatrangefield = NumericRange(1.5, 5.5)
+ datetimerangefield = DateTimeRange(datetime(2024, 1, 1), datetime(2024, 12, 31))
+ daterangefield = DateRange(date(2024, 1, 1), date(2024, 12, 31))
def arrayfield_tests(self):
sorted_array = self.arrayfield.sort()
diff --git a/pylint_django/tests/input/external_psycopg3_noerror_postgres_fields.py b/pylint_django/tests/input/external_psycopg3_noerror_postgres_fields.py
index 5febb28..61e25cf 100644
--- a/pylint_django/tests/input/external_psycopg3_noerror_postgres_fields.py
+++ b/pylint_django/tests/input/external_psycopg3_noerror_postgres_fields.py
@@ -4,12 +4,13 @@ Checks that Pylint does not complain Postgres model fields.
# pylint: disable=C0111,W5101
from __future__ import print_function
-from django.contrib.postgres import fields
+from datetime import date
+from psycopg.types.range import DateRange
from django.db import models
class PostgresFieldsModel(models.Model):
- period = fields.DateRangeField(null=False, blank=False)
+ period = DateRange(date(2024, 1, 1), date(2024, 12, 31))
def rangefield_tests(self):
print(self.period.lower)
Metadata
Metadata
Assignees
Labels
No labels