Skip to content

Add support for QuerySet.dates() and datetimes() #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: 'mongodb-forks/django'
ref: 'mongodb-5.1.x'
ref: 'mongodb-5.1.x-convert_truncated_datetime'
path: 'django_repo'
persist-credentials: false
- name: Install system packages for Django's Python test dependencies
Expand Down
9 changes: 0 additions & 9 deletions django_mongodb_backend/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,6 @@ def cursor_iter(self, cursor, chunk_size, columns):

def check_query(self):
"""Check if the current query is supported by the database."""
if self.query.distinct:
# This is a heuristic to detect QuerySet.datetimes() and dates().
# "datetimefield" and "datefield" are the names of the annotations
# the methods use. A user could annotate with the same names which
# would give an incorrect error message.
if "datetimefield" in self.query.annotations:
raise NotSupportedError("QuerySet.datetimes() is not supported on MongoDB.")
if "datefield" in self.query.annotations:
raise NotSupportedError("QuerySet.dates() is not supported on MongoDB.")
if self.query.extra:
if any(key.startswith("_prefetch_related_") for key in self.query.extra):
raise NotSupportedError("QuerySet.prefetch_related() is not supported on MongoDB.")
Expand Down
76 changes: 1 addition & 75 deletions django_mongodb_backend/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,81 +272,6 @@ def django_test_expected_failures(self):
"update.tests.AdvancedTests.test_update_ordered_by_m2m_annotation",
"update.tests.AdvancedTests.test_update_ordered_by_m2m_annotation_desc",
},
"QuerySet.dates() is not supported on MongoDB.": {
"admin_changelist.tests.ChangeListTests.test_computed_list_display_localization",
"admin_changelist.tests.ChangeListTests.test_object_tools_displayed_no_add_permission",
"admin_views.tests.AdminViewBasicTest.test_change_list_sorting_override_model_admin",
"admin_views.tests.AdminViewBasicTest.test_multiple_sort_same_field",
"admin_views.tests.AdminViewListEditable.test_inheritance",
"admin_views.tests.CSSTest.test_changelist_field_classes",
"admin_views.tests.DateHierarchyTests",
"aggregation.tests.AggregateTestCase.test_dates_with_aggregation",
"annotations.tests.AliasTests.test_dates_alias",
"aggregation_regress.tests.AggregationTests.test_more_more_more2",
"backends.tests.DateQuotingTest.test_django_date_trunc",
"dates.tests.DatesTests.test_dates_trunc_datetime_fields",
"dates.tests.DatesTests.test_related_model_traverse",
"generic_views.test_dates.ArchiveIndexViewTests.test_allow_empty_archive_view",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_by_month",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_context_object_name",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_custom_sorting",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_custom_sorting_dec",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_template",
"generic_views.test_dates.ArchiveIndexViewTests.test_archive_view_template_suffix",
"generic_views.test_dates.ArchiveIndexViewTests.test_date_list_order",
"generic_views.test_dates.ArchiveIndexViewTests.test_no_duplicate_query",
"generic_views.test_dates.ArchiveIndexViewTests.test_paginated_archive_view",
"generic_views.test_dates.ArchiveIndexViewTests.test_paginated_archive_view_does_not_load_entire_table",
"generic_views.test_dates.MonthArchiveViewTests.test_custom_month_format",
"generic_views.test_dates.MonthArchiveViewTests.test_date_list_order",
"generic_views.test_dates.MonthArchiveViewTests.test_month_view",
"generic_views.test_dates.MonthArchiveViewTests.test_month_view_allow_empty",
"generic_views.test_dates.MonthArchiveViewTests.test_month_view_allow_future",
"generic_views.test_dates.MonthArchiveViewTests.test_month_view_get_month_from_request",
"generic_views.test_dates.MonthArchiveViewTests.test_month_view_paginated",
"generic_views.test_dates.MonthArchiveViewTests.test_previous_month_without_content",
"generic_views.test_dates.YearArchiveViewTests.test_date_list_order",
"generic_views.test_dates.YearArchiveViewTests.test_get_context_data_receives_extra_context",
"generic_views.test_dates.YearArchiveViewTests.test_no_duplicate_query",
"generic_views.test_dates.YearArchiveViewTests.test_year_view",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_allow_future",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_custom_sort_order",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_empty",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_make_object_list",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_paginated",
"generic_views.test_dates.YearArchiveViewTests.test_year_view_two_custom_sort_orders",
"many_to_one.tests.ManyToOneTests.test_select_related",
"model_regress.tests.ModelTests.test_date_filter_null",
"reserved_names.tests.ReservedNameTests.test_dates",
"queryset_pickle.tests.PickleabilityTestCase.test_specialized_queryset",
},
"QuerySet.datetimes() is not supported on MongoDB.": {
"admin_views.test_templatetags.DateHierarchyTests",
"admin_views.test_templatetags.AdminTemplateTagsTest.test_override_change_list_template_tags",
"admin_views.tests.AdminViewBasicTest.test_date_hierarchy_empty_queryset",
"admin_views.tests.AdminViewBasicTest.test_date_hierarchy_local_date_differ_from_utc",
"admin_views.tests.AdminViewBasicTest.test_date_hierarchy_timezone_dst",
"annotations.tests.AliasTests.test_datetimes_alias",
"datetimes.tests.DateTimesTests.test_21432",
"datetimes.tests.DateTimesTests.test_datetimes_has_lazy_iterator",
"datetimes.tests.DateTimesTests.test_datetimes_returns_available_dates_for_given_scope_and_given_field",
"datetimes.tests.DateTimesTests.test_related_model_traverse",
"generic_views.test_dates.ArchiveIndexViewTests.test_aware_datetime_archive_view",
"generic_views.test_dates.ArchiveIndexViewTests.test_datetime_archive_view",
"generic_views.test_dates.MonthArchiveViewTests.test_aware_datetime_month_view",
"generic_views.test_dates.MonthArchiveViewTests.test_datetime_month_view",
"generic_views.test_dates.YearArchiveViewTests.test_aware_datetime_year_view",
"generic_views.test_dates.YearArchiveViewTests.test_datetime_year_view",
"model_inheritance_regress.tests.ModelInheritanceTest.test_issue_7105",
"queries.tests.Queries1Tests.test_ticket7155",
"queries.tests.Queries1Tests.test_ticket7791",
"queries.tests.Queries1Tests.test_tickets_6180_6203",
"queries.tests.Queries1Tests.test_tickets_7087_12242",
"timezones.tests.LegacyDatabaseTests.test_query_datetimes",
"timezones.tests.NewDatabaseTests.test_query_datetimes",
"timezones.tests.NewDatabaseTests.test_query_datetimes_in_other_timezone",
},
"QuerySet.extra() is not supported.": {
"aggregation.tests.AggregateTestCase.test_exists_extra_where_with_aggregate",
"annotations.tests.NonAggregateAnnotationTestCase.test_column_field_ordering",
Expand All @@ -366,6 +291,7 @@ def django_test_expected_failures(self):
"queries.test_qs_combinators.QuerySetSetOperationTests.test_union_with_extra_and_values_list",
"queries.tests.EscapingTests.test_ticket_7302",
"queries.tests.Queries1Tests.test_tickets_1878_2939",
"queries.tests.Queries1Tests.test_tickets_7087_12242",
"queries.tests.Queries5Tests.test_extra_select_literal_percent_s",
"queries.tests.Queries5Tests.test_ticket7256",
"queries.tests.ValuesQuerysetTests.test_extra_multiple_select_params_values_order_by",
Expand Down
3 changes: 3 additions & 0 deletions django_mongodb_backend/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def convert_uuidfield_value(self, value, expression, connection):
value = uuid.UUID(value)
return value

def convert_truncated_datetime(self, value, tzinfo):
return value

def combine_expression(self, connector, sub_expressions):
lhs, rhs = sub_expressions
if connector == Combinable.BITLEFTSHIFT:
Expand Down
2 changes: 0 additions & 2 deletions docs/source/ref/models/querysets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ All of Django's :doc:`QuerySet methods <django:ref/models/querysets>` are
supported, except:

- :meth:`bulk_update() <django.db.models.query.QuerySet.bulk_update>`
- :meth:`dates() <django.db.models.query.QuerySet.dates>`
- :meth:`datetimes() <django.db.models.query.QuerySet.datetimes>`
- :meth:`extra() <django.db.models.query.QuerySet.extra>`
- :meth:`prefetch_related() <django.db.models.query.QuerySet.prefetch_related>`

Expand Down
5 changes: 3 additions & 2 deletions docs/source/topics/known-issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ Querying
- The following ``QuerySet`` methods aren't supported:

- :meth:`bulk_update() <django.db.models.query.QuerySet.bulk_update>`
- :meth:`dates() <django.db.models.query.QuerySet.dates>`
- :meth:`datetimes() <django.db.models.query.QuerySet.datetimes>`
- :meth:`extra() <django.db.models.query.QuerySet.extra>`
- :meth:`prefetch_related() <django.db.models.query.QuerySet.prefetch_related>`

- :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>` may
generate incorrect results. XXX TODO XXX

- :meth:`QuerySet.delete() <django.db.models.query.QuerySet.delete>` and
:meth:`update() <django.db.models.query.QuerySet.update>` do not support queries
that span multiple collections.
Expand Down