Skip to content

INTPYTHON-348 Update raw_query tests for raw_mql #10

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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a017deb
Update GenericForeignKey object_id to CharField/TextField
timgraham Jul 17, 2024
9152f83
use ObjectIdAutoField in test models
timgraham Jul 17, 2024
c565caf
update serializer output for MongoAutoField
timgraham Jul 18, 2024
36b1030
comment out usage of QuerySet.extra()
timgraham Jul 18, 2024
c09a3b8
remove unsupported usage of nulls_first
timgraham Jul 22, 2024
e124a7b
aggregation, aggregation_regress edits
timgraham Aug 19, 2024
871fa74
add test for ModelForm data using numeric pks
timgraham Aug 16, 2024
4e34ee4
drop requirement that QuerySet.explain() log a query
timgraham Aug 16, 2024
abfd5cb
schema and migrations test edits
timgraham Aug 24, 2024
b08f3f1
backends edits
timgraham Aug 29, 2024
c1627fe
introspection test edits
timgraham Aug 27, 2024
0f68e6f
Added supports_sequence_reset skip in backends tests.
timgraham Aug 23, 2024
953dbf3
remove SQL introspection from queries tests
timgraham Sep 3, 2024
26dabbb
Added QuerySet.union() test with renames.
WaVEV Sep 7, 2024
9ba649b
Fixed #35815 -- Allowed db_default to be a literal.
timgraham Oct 9, 2024
553b35d
edits for many test apps
timgraham Sep 26, 2024
b4b95ab
indexes
timgraham Oct 14, 2024
0354694
add skip for partial index support
timgraham Oct 17, 2024
aa10dfd
fix "view on site" for non-integer pks
timgraham Oct 17, 2024
0dde152
allow runtests.py to discover tests in django_mongodb/tests
timgraham Oct 22, 2024
fa62156
INTPYTHON-348 Update raw_query tests for raw_mql
aclark4life Oct 28, 2024
98a6cce
INTPYTHON-348 Update raw_query tests for raw_mql
aclark4life Nov 5, 2024
7b822c2
Revert "INTPYTHON-348 Update raw_query tests for raw_mql"
aclark4life Nov 6, 2024
4874aee
INTPYTHON-348 Update raw_query tests for raw_mql
aclark4life Nov 6, 2024
fda8f96
INTPYTHON-348 add support for QuerySet.raw()
aclark4life Nov 7, 2024
b4687dc
INTPYTHON-348 Update raw_query tests for raw_mql
aclark4life Nov 8, 2024
7a46121
INTPYTHON-348 Update raw_query tests for raw_mql
aclark4life Nov 8, 2024
65d64eb
INTPYTHON-348 Add support for QuerySet.raw()
aclark4life Nov 9, 2024
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 django/contrib/admin/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def wrapper(*args, **kwargs):
path("autocomplete/", wrap(self.autocomplete_view), name="autocomplete"),
path("jsi18n/", wrap(self.i18n_javascript, cacheable=True), name="jsi18n"),
path(
"r/<int:content_type_id>/<path:object_id>/",
"r/<str:content_type_id>/<path:object_id>/",
wrap(contenttype_views.shortcut),
name="view_on_site",
),
Expand Down
4 changes: 3 additions & 1 deletion django/contrib/sites/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django_mongodb.fields import ObjectIdAutoField

import django.contrib.sites.models
from django.contrib.sites.models import _simple_domain_name_validator
from django.db import migrations, models
Expand All @@ -12,7 +14,7 @@ class Migration(migrations.Migration):
fields=[
(
"id",
models.AutoField(
ObjectIdAutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
Expand Down
5 changes: 4 additions & 1 deletion django/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ def _check_db_default(self, databases=None, **kwargs):

if (
self.db_default is NOT_PROVIDED
or isinstance(self.db_default, Value)
or (
isinstance(self.db_default, Value)
or not hasattr(self.db_default, "resolve_expression")
)
or databases is None
):
return []
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_filters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class TaggedItem(models.Model):
content_type = models.ForeignKey(
ContentType, models.CASCADE, related_name="tagged_items"
)
object_id = models.PositiveIntegerField()
object_id = models.TextField()
content_object = GenericForeignKey("content_type", "object_id")

def __str__(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/admin_filters/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def test_relatedfieldlistfilter_foreignkey(self):
choice = select_by(filterspec.choices(changelist), "display", "alfred")
self.assertIs(choice["selected"], True)
self.assertEqual(
choice["query_string"], "?author__id__exact=%d" % self.alfred.pk
choice["query_string"], "?author__id__exact=%s" % self.alfred.pk
)

def test_relatedfieldlistfilter_foreignkey_ordering(self):
Expand Down Expand Up @@ -803,7 +803,7 @@ def test_relatedfieldlistfilter_manytomany(self):
choice = select_by(filterspec.choices(changelist), "display", "bob")
self.assertIs(choice["selected"], True)
self.assertEqual(
choice["query_string"], "?contributors__id__exact=%d" % self.bob.pk
choice["query_string"], "?contributors__id__exact=%s" % self.bob.pk
)

def test_relatedfieldlistfilter_reverse_relationships(self):
Expand Down Expand Up @@ -839,7 +839,7 @@ def test_relatedfieldlistfilter_reverse_relationships(self):
)
self.assertIs(choice["selected"], True)
self.assertEqual(
choice["query_string"], "?books_authored__id__exact=%d" % self.bio_book.pk
choice["query_string"], "?books_authored__id__exact=%s" % self.bio_book.pk
)

# M2M relationship -----
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_relatedfieldlistfilter_reverse_relationships(self):
self.assertIs(choice["selected"], True)
self.assertEqual(
choice["query_string"],
"?books_contributed__id__exact=%d" % self.django_book.pk,
"?books_contributed__id__exact=%s" % self.django_book.pk,
)

# With one book, the list filter should appear because there is also a
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_inlines/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Child(models.Model):
teacher = models.ForeignKey(Teacher, models.CASCADE)

content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.PositiveIntegerField()
object_id = models.TextField()
parent = GenericForeignKey()

def __str__(self):
Expand Down
12 changes: 6 additions & 6 deletions tests/admin_inlines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def test_inline_change_m2m_change_perm(self):
)
self.assertContains(
response,
'<input type="hidden" id="id_Author_books-0-id" value="%i" '
'<input type="hidden" id="id_Author_books-0-id" value="%s" '
'name="Author_books-0-id">' % self.author_book_auto_m2m_intermediate_id,
html=True,
)
Expand All @@ -1093,7 +1093,7 @@ def test_inline_change_fk_add_perm(self):
)
self.assertNotContains(
response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" '
'<input type="hidden" id="id_inner2_set-0-id" value="%s" '
'name="inner2_set-0-id">' % self.inner2.id,
html=True,
)
Expand All @@ -1115,7 +1115,7 @@ def test_inline_change_fk_change_perm(self):
)
self.assertContains(
response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" '
'<input type="hidden" id="id_inner2_set-0-id" value="%s" '
'name="inner2_set-0-id">' % self.inner2.id,
html=True,
)
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def test_inline_change_fk_add_change_perm(self):
)
self.assertContains(
response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" '
'<input type="hidden" id="id_inner2_set-0-id" value="%s" '
'name="inner2_set-0-id">' % self.inner2.id,
html=True,
)
Expand All @@ -1184,7 +1184,7 @@ def test_inline_change_fk_change_del_perm(self):
)
self.assertContains(
response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" '
'<input type="hidden" id="id_inner2_set-0-id" value="%s" '
'name="inner2_set-0-id">' % self.inner2.id,
html=True,
)
Expand Down Expand Up @@ -1215,7 +1215,7 @@ def test_inline_change_fk_all_perms(self):
)
self.assertContains(
response,
'<input type="hidden" id="id_inner2_set-0-id" value="%i" '
'<input type="hidden" id="id_inner2_set-0-id" value="%s" '
'name="inner2_set-0-id">' % self.inner2.id,
html=True,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_utils/test_logentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_logentry_get_admin_url(self):
"admin:admin_utils_article_change", args=(quote(self.a1.pk),)
)
self.assertEqual(logentry.get_admin_url(), expected_url)
self.assertIn("article/%d/change/" % self.a1.pk, logentry.get_admin_url())
self.assertIn("article/%s/change/" % self.a1.pk, logentry.get_admin_url())

logentry.content_type.model = "nonexistent"
self.assertIsNone(logentry.get_admin_url())
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class PostAdmin(admin.ModelAdmin):
@admin.display
def coolness(self, instance):
if instance.pk:
return "%d amount of cool." % instance.pk
return "%s amount of cool." % instance.pk
else:
return "Unknown coolness."

Expand Down
10 changes: 6 additions & 4 deletions tests/admin_views/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import tempfile
import uuid

from django_mongodb.fields import ObjectIdAutoField

from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
Expand Down Expand Up @@ -444,7 +446,7 @@ class DooHickey(models.Model):


class Grommet(models.Model):
code = models.AutoField(primary_key=True)
code = ObjectIdAutoField(primary_key=True)
owner = models.ForeignKey(Collector, models.CASCADE)
name = models.CharField(max_length=100)

Expand Down Expand Up @@ -545,7 +547,7 @@ class FunkyTag(models.Model):
"Because we all know there's only one real use case for GFKs."
name = models.CharField(max_length=25)
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.PositiveIntegerField()
object_id = models.TextField()
content_object = GenericForeignKey("content_type", "object_id")

def __str__(self):
Expand Down Expand Up @@ -684,7 +686,7 @@ class Bonus(models.Model):


class Question(models.Model):
big_id = models.BigAutoField(primary_key=True)
big_id = ObjectIdAutoField(primary_key=True)
question = models.CharField(max_length=20)
posted = models.DateField(default=datetime.date.today)
expires = models.DateTimeField(null=True, blank=True)
Expand Down Expand Up @@ -1048,7 +1050,7 @@ class ImplicitlyGeneratedPK(models.Model):
# Models for #25622
class ReferencedByGenRel(models.Model):
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
object_id = models.TextField()
content_object = GenericForeignKey("content_type", "object_id")


Expand Down
22 changes: 11 additions & 11 deletions tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def test_disallowed_filtering(self):
response = self.client.get(reverse("admin:admin_views_workhour_changelist"))
self.assertContains(response, "employee__person_ptr__exact")
response = self.client.get(
"%s?employee__person_ptr__exact=%d"
"%s?employee__person_ptr__exact=%s"
% (reverse("admin:admin_views_workhour_changelist"), e1.pk)
)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -4524,13 +4524,13 @@ def test_pk_hidden_fields(self):
self.assertContains(
response,
'<div class="hiddenfields">\n'
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n'
'<input type="hidden" name="form-0-id" value="%s" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%s" id="id_form-1-id">\n'
"</div>" % (story2.id, story1.id),
html=True,
)
self.assertContains(response, '<td class="field-id">%d</td>' % story1.id, 1)
self.assertContains(response, '<td class="field-id">%d</td>' % story2.id, 1)
self.assertContains(response, '<td class="field-id">%s</td>' % story1.id, 1)
self.assertContains(response, '<td class="field-id">%s</td>' % story2.id, 1)

def test_pk_hidden_fields_with_list_display_links(self):
"""Similarly as test_pk_hidden_fields, but when the hidden pk fields are
Expand All @@ -4554,19 +4554,19 @@ def test_pk_hidden_fields_with_list_display_links(self):
self.assertContains(
response,
'<div class="hiddenfields">\n'
'<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%d" id="id_form-1-id">\n'
'<input type="hidden" name="form-0-id" value="%s" id="id_form-0-id">'
'<input type="hidden" name="form-1-id" value="%s" id="id_form-1-id">\n'
"</div>" % (story2.id, story1.id),
html=True,
)
self.assertContains(
response,
'<th class="field-id"><a href="%s">%d</a></th>' % (link1, story1.id),
'<th class="field-id"><a href="%s">%s</a></th>' % (link1, story1.id),
1,
)
self.assertContains(
response,
'<th class="field-id"><a href="%s">%d</a></th>' % (link2, story2.id),
'<th class="field-id"><a href="%s">%s</a></th>' % (link2, story2.id),
1,
)

Expand Down Expand Up @@ -4890,7 +4890,7 @@ def setUpTestData(cls):
cls.superuser = User.objects.create_superuser(
username="super", password="secret", email="[email protected]"
)
cls.pks = [EmptyModel.objects.create().id for i in range(3)]
cls.pks = [EmptyModel.objects.create(id=i + 1).id for i in range(3)]

def setUp(self):
self.client.force_login(self.superuser)
Expand Down Expand Up @@ -6803,7 +6803,7 @@ def test_readonly_get(self):
response = self.client.get(
reverse("admin:admin_views_post_change", args=(p.pk,))
)
self.assertContains(response, "%d amount of cool" % p.pk)
self.assertContains(response, "%s amount of cool" % p.pk)

@ignore_warnings(category=RemovedInDjango60Warning)
def test_readonly_text_field(self):
Expand Down
25 changes: 12 additions & 13 deletions tests/aggregation/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,11 +1420,10 @@ def test_aggregation_subquery_annotation(self):
publisher_qs = Publisher.objects.annotate(
latest_book_pubdate=Subquery(latest_book_pubdate_qs),
).annotate(count=Count("book"))
with self.assertNumQueries(1) as ctx:
list(publisher_qs)
self.assertEqual(ctx[0]["sql"].count("SELECT"), 2)
list(publisher_qs)
# self.assertEqual(ctx[0]["sql"].count("SELECT"), 2)
# The GROUP BY should not be by alias either.
self.assertEqual(ctx[0]["sql"].lower().count("latest_book_pubdate"), 1)
# self.assertEqual(ctx[0]["sql"].lower().count("latest_book_pubdate"), 1)

def test_aggregation_subquery_annotation_exists(self):
latest_book_pubdate_qs = (
Expand Down Expand Up @@ -1659,10 +1658,10 @@ def test_aggregation_subquery_annotation_related_field(self):
)
.annotate(count=Count("authors"))
)
with self.assertNumQueries(1) as ctx:
with self.assertNumQueries(1):
self.assertSequenceEqual(books_qs, [book])
if connection.features.allows_group_by_select_index:
self.assertEqual(ctx[0]["sql"].count("SELECT"), 3)
# if connection.features.allows_group_by_select_index:
# self.assertEqual(ctx[0]["sql"].count("SELECT"), 3)

@skipUnlessDBFeature("supports_subqueries_in_group_by")
def test_aggregation_nested_subquery_outerref(self):
Expand Down Expand Up @@ -2246,7 +2245,7 @@ def test_referenced_subquery_requires_wrapping(self):
.filter(author=OuterRef("pk"))
.annotate(total=Count("book"))
)
with self.assertNumQueries(1) as ctx:
with self.assertNumQueries(1):
aggregate = (
Author.objects.annotate(
total_books=Subquery(total_books_qs.values("total"))
Expand All @@ -2256,8 +2255,8 @@ def test_referenced_subquery_requires_wrapping(self):
sum_total_books=Sum("total_books"),
)
)
sql = ctx.captured_queries[0]["sql"].lower()
self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
# sql = ctx.captured_queries[0]["sql"].lower()
# self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
self.assertEqual(aggregate, {"sum_total_books": 3})

def test_referenced_composed_subquery_requires_wrapping(self):
Expand All @@ -2266,7 +2265,7 @@ def test_referenced_composed_subquery_requires_wrapping(self):
.filter(author=OuterRef("pk"))
.annotate(total=Count("book"))
)
with self.assertNumQueries(1) as ctx:
with self.assertNumQueries(1):
aggregate = (
Author.objects.annotate(
total_books=Subquery(total_books_qs.values("total")),
Expand All @@ -2277,8 +2276,8 @@ def test_referenced_composed_subquery_requires_wrapping(self):
sum_total_books=Sum("total_books_ref"),
)
)
sql = ctx.captured_queries[0]["sql"].lower()
self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
# sql = ctx.captured_queries[0]["sql"].lower()
# self.assertEqual(sql.count("select"), 3, "Subquery wrapping required")
self.assertEqual(aggregate, {"sum_total_books": 3})

@skipUnlessDBFeature("supports_over_clause")
Expand Down
10 changes: 6 additions & 4 deletions tests/aggregation_regress/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django_mongodb.fields import ObjectIdAutoField

from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models
Expand All @@ -17,7 +19,7 @@ class Publisher(models.Model):
class ItemTag(models.Model):
tag = models.CharField(max_length=100)
content_type = models.ForeignKey(ContentType, models.CASCADE)
object_id = models.PositiveIntegerField()
object_id = models.CharField(max_length=24)
content_object = GenericForeignKey("content_type", "object_id")


Expand Down Expand Up @@ -45,13 +47,13 @@ class Store(models.Model):


class Entries(models.Model):
EntryID = models.AutoField(primary_key=True, db_column="Entry ID")
EntryID = ObjectIdAutoField(primary_key=True, db_column="Entry ID")
Entry = models.CharField(unique=True, max_length=50)
Exclude = models.BooleanField(default=False)


class Clues(models.Model):
ID = models.AutoField(primary_key=True)
ID = ObjectIdAutoField(primary_key=True)
EntryID = models.ForeignKey(
Entries, models.CASCADE, verbose_name="Entry", db_column="Entry ID"
)
Expand All @@ -63,7 +65,7 @@ class WithManualPK(models.Model):
# classes with the same PK value, and there are some (external)
# DB backends that don't work nicely when assigning integer to AutoField
# column (MSSQL at least).
id = models.IntegerField(primary_key=True)
id = ObjectIdAutoField(primary_key=True)


class HardbackBook(Book):
Expand Down
Loading