Skip to content

Commit

Permalink
fix: cast datetime.datetime to DateTimeField as required by Coalesce()
Browse files Browse the repository at this point in the history
ENT-9941
  • Loading branch information
pwnage101 committed Feb 3, 2025
1 parent 25e83be commit ac8cfbf
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from datetime import timedelta

from django.core.management import BaseCommand, CommandError
from django.db.models import Max
from django.db.models.functions import Coalesce, Greatest
from django.db.models import DateTimeField, Max
from django.db.models.functions import Cast, Coalesce, Greatest
from django.utils import timezone

from enterprise.content_metadata.api import get_and_cache_customer_content_metadata
Expand Down Expand Up @@ -100,8 +100,9 @@ def handle(self, *args, **options):
Max("enterprise_customer__enterprise_customer_catalogs__modified"),
Coalesce(
Max("enterprise_customer__enterprise_customer_catalogs__enterprise_catalog_query__modified"),
# Arbitrarily default to 1 year ago. Greatest() in MySQL relies on all inputs being non-null.
timezone.now() - timedelta(days=360),
# Note 1: Arbitrarily fallback to 1 year ago because Greatest() in MySQL relies on non-null inputs.
# Note 2: Cast python datetime to django field type, or else experience weird errors in prod.
Cast(timezone.now() - timedelta(days=360), DateTimeField())
)
)
)
Expand Down

0 comments on commit ac8cfbf

Please sign in to comment.