Skip to content

Commit

Permalink
Merge pull request #486 from openedx/saleem-latif/ENT-9372-fixes
Browse files Browse the repository at this point in the history
fix: Fixed a datetime conversion error appearing on production.
  • Loading branch information
saleem-latif authored Aug 29, 2024
2 parents 41ecfd6 + 502a678 commit a4f97ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Unreleased
----------

=========================
[8.11.1] - 2024-08-29
---------------------
* fix: Fixed a datetime conversion error appearing on production.

[8.11.0] - 2024-08-29
---------------------
* perf: Performance enhancements for admin analytics aggregates endpoint.
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Enterprise data api application. This Django app exposes API endpoints used by enterprises.
"""

__version__ = "8.11.0"
__version__ = "8.11.1"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Module for interacting with the fact_enrollment_admin_dash table.
"""
from datetime import date
from datetime import date, datetime
from uuid import UUID

from ..queries import FactEnrollmentAdminDashQueries
Expand All @@ -23,13 +23,22 @@ def get_enrollment_date_range(self, enterprise_customer_uuid: UUID):
enterprise_customer_uuid (UUID): The UUID of the enterprise customer.
Returns:
(tuple<int, int>): The minimum and maximum enrollment dates.
(tuple<date, date>): The minimum and maximum enrollment dates.
"""
results = run_query(
query=self.queries.get_enrollment_date_range_query(),
params={'enterprise_customer_uuid': enterprise_customer_uuid}
)
return tuple(results[0])
min_date, max_date = results[0]

# We should return date objects, not datetime objects
# This is done to counter cases where database values are datetime objects.
if min_date and isinstance(min_date, datetime):
min_date = min_date.date()
if max_date and isinstance(max_date, datetime):
max_date = max_date.date()

return min_date, max_date

def get_enrollment_and_course_count(self, enterprise_customer_uuid: UUID, start_date: date, end_date: date):
"""
Expand Down
8 changes: 5 additions & 3 deletions enterprise_data/api/v1/views/enterprise_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def get(self, request, enterprise_id):
"""
HTTP GET endpoint to retrieve the enterprise admin aggregate data.
"""
# Validate the enterprise_id
enterprise_id = enterprise_id.replace('-', '')
serializer = serializers.AdminAnalyticsAggregatesQueryParamsSerializer(
data=request.GET
)
Expand All @@ -106,7 +108,7 @@ def get(self, request, enterprise_id):
)

start_date = serializer.data.get(
'start_date', min_enrollment_date.date()
'start_date', min_enrollment_date
)
end_date = serializer.data.get('end_date', datetime.today())

Expand All @@ -128,8 +130,8 @@ def get(self, request, enterprise_id):
'hours': hours,
'sessions': sessions,
'last_updated_at': last_updated_at.date() if last_updated_at else None,
'min_enrollment_date': min_enrollment_date.date(),
'max_enrollment_date': max_enrollment_date.date(),
'min_enrollment_date': min_enrollment_date,
'max_enrollment_date': max_enrollment_date,
},
status=HTTP_200_OK,
)
Expand Down

0 comments on commit a4f97ca

Please sign in to comment.