[Django] #30359: Possible access to unintended variable in "django/tests/contenttypes_tests/test_models.py" line 128

2 views
Skip to first unread message

Django

unread,
Apr 12, 2019, 8:31:25 AM4/12/19
to django-...@googlegroups.com
#30359: Possible access to unintended variable in
"django/tests/contenttypes_tests/test_models.py" line 128
-----------------------------------------+------------------------
Reporter: petrufm | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
While experimenting with a CodeSonar plugin we develop, we noticed a
potential bug in file "django/tests/contenttypes_tests/test_models.py"
line 128 function test_get_for_concrete_model.

self.assertEqual(concrete_model_ct,
ContentType.objects.get_for_model(DeferredProxyModel)) <<<<<<HERE
self.assertEqual(
proxy_model_ct,
ContentType.objects.get_for_model(DeferredProxyModel,
for_concrete_model=False)

Shouldn't you use proxy_model_ct instead of concrete_model_ct in the first
line (as it is used in the second)?

Thanks,
Petru-Florin Mihancea

--
Ticket URL: <https://code.djangoproject.com/ticket/30359>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 12, 2019, 8:55:24 AM4/12/19
to django-...@googlegroups.com
#30359: Possible access to unintended variable in
"django/tests/contenttypes_tests/test_models.py" line 128
-------------------------------------+-------------------------------------
Reporter: petrufm | Owner: nobody
Type: Bug | Status: closed
Component: | Version: master
contrib.contenttypes |
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* component: Uncategorized => contrib.contenttypes
* resolution: => invalid


Old description:

> While experimenting with a CodeSonar plugin we develop, we noticed a
> potential bug in file "django/tests/contenttypes_tests/test_models.py"
> line 128 function test_get_for_concrete_model.
>
> self.assertEqual(concrete_model_ct,
> ContentType.objects.get_for_model(DeferredProxyModel)) <<<<<<HERE
> self.assertEqual(
> proxy_model_ct,
> ContentType.objects.get_for_model(DeferredProxyModel,
> for_concrete_model=False)
>
> Shouldn't you use proxy_model_ct instead of concrete_model_ct in the
> first line (as it is used in the second)?
>
> Thanks,
> Petru-Florin Mihancea

New description:

While experimenting with a CodeSonar plugin we develop, we noticed a
potential bug in file "django/tests/contenttypes_tests/test_models.py"
line 128 function test_get_for_concrete_model.
{{{
self.assertEqual(concrete_model_ct,
ContentType.objects.get_for_model(DeferredProxyModel)) <<<<<<HERE
self.assertEqual(
proxy_model_ct,
ContentType.objects.get_for_model(DeferredProxyModel,
for_concrete_model=False)
}}}
Shouldn't you use proxy_model_ct instead of concrete_model_ct in the first
line (as it is used in the second)?

Thanks,
Petru-Florin Mihancea

--

Comment:

The test doesn't pass with that change.
`ContentType.objects.get_for_model()` defaults to
`for_concrete_model=True` so the behavior looks correct.

--
Ticket URL: <https://code.djangoproject.com/ticket/30359#comment:1>

Reply all
Reply to author
Forward
0 new messages