Chore: Import dateparser lazily so processes that never parse dates skip it

This commit is contained in:
Trenton H committed 2026-10-30 10:21:35 -07:00
1 parent e240c89f27
commit 28f54bb592
6 files changed
+16 -11

No files matched your search

+2 -1
View File
@@ -11,7 +11,6 @@ from decimal import InvalidOperation
from typing import TYPE_CHECKING
from typing import Any
import dateparser
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import Case
@@ -350,6 +349,8 @@ class DateQueryField(serializers.DateField):
if not isinstance(value, str):
raise
import dateparser
try:
parsed = dateparser.parse(
value,
+2 -2
View File
@@ -7,8 +7,6 @@ from dataclasses import dataclass
from types import TracebackType
from typing import Self
import dateparser
logger = logging.getLogger(__name__)
@@ -80,6 +78,8 @@ class DateParserPluginBase(ABC):
Uses configuration from `self.config`.
"""
import dateparser
try:
return dateparser.parse(
date_string,
@@ -71,7 +71,7 @@ class TestParseString:
):
# We still need to mock dateparser.parse to force the exception
mocker.patch(
"documents.plugins.date_parsing.base.dateparser.parse",
"dateparser.parse",
side_effect=ValueError(
"Parsing error: 01/01/2024",
),
@@ -260,7 +260,7 @@ class TestRegexDateParser:
parser = RegexDateParserPlugin(base_config)
# Patch the dateparser.parse
target = "documents.plugins.date_parsing.base.dateparser.parse"
target = "dateparser.parse"
def fake_parse(
date_string: str,
@@ -335,7 +335,7 @@ class TestRegexDateParser:
)
parser = RegexDateParserPlugin(cfg)
target = "documents.plugins.date_parsing.base.dateparser.parse"
target = "dateparser.parse"
def fake_parse(
date_string: str,
@@ -400,7 +400,7 @@ class TestRegexDateParser:
parser = RegexDateParserPlugin(cfg)
# Patch the module's dateparser.parse so we can inspect calls
target = "documents.plugins.date_parsing.base.dateparser.parse"
target = "dateparser.parse"
def fake_parse(
date_string: str,