From 605d7ed74d55a6ab16cc8ea71fff5552cbb80f91 Mon Sep 17 00:00:00 2001 From: TarunSinghChauhan Date: Tue, 25 Aug 2026 03:15:50 +0000 Subject: [PATCH] Fix datetime_utils.parse accepting truncated datetimes The hour-only-offset retry (which appends :00 to complete offsets like +01 -> +01:00) was unguarded, so it also fired for any string that failed every format in available_formats - including truncated datetimes like '2024-06-15 12' or '2024-06-15T12:30'. These would get :00 appended and accidentally match a valid format, causing local mode to silently accept input that a real Qdrant instance rejects. Guarded the retry to only fire when the string actually ends in an hour-only UTC offset ([+-]HH). Verified against all four cases from the issue: truncated hour and truncated minute now correctly return None, while the hour-only-offset and valid full date cases still parse correctly. Fixes #1349. --- qdrant_client/local/datetime_utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qdrant_client/local/datetime_utils.py b/qdrant_client/local/datetime_utils.py index c2f957195..714fe5afb 100644 --- a/qdrant_client/local/datetime_utils.py +++ b/qdrant_client/local/datetime_utils.py @@ -1,3 +1,4 @@ +import re from datetime import datetime, timezone # These are the formats accepted by qdrant core @@ -46,4 +47,12 @@ def parse_available_formats(datetime_str: str) -> datetime | None: # dt examples to handle: # "2021-01-01 00:00:00.000+01" # "2021-01-01 00:00:00.000-10" - return parse_available_formats(date_str + ":00") + # This retry must only fire for an actual hour-only UTC offset at the end of + # the string (e.g. "+01" or "-10"). Without this guard, any string that fails + # every format above (including truncated datetimes like "2024-06-15 12" or + # "2024-06-15T12:30") would also get ":00" appended and could accidentally + # match a valid format, silently accepting input that qdrant core rejects. + if re.search(r"[+-]\d{2}$", date_str): + return parse_available_formats(date_str + ":00") + + return None