#21436: 1.5.1 returns "object has no attribute '_known_related_objects'" when
using
the bitwise or operator with objects.get()
-------------------------------------+-------------------------------------
Reporter: mamalos | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Keywords: bitwise or, model, get,
Severity: Normal | filter
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hi all,
I am running this code on django 1.5.1:
{{{
low_afpr = Result2.objects.filter(metric='afpr', value__lte=0.01,
window_size__gte=1000)
high_tpr_low_afpr = []
for x in low_afpr_list:
if Result2.objects.filter(alg=x.alg, metric='all_commands',
nmixtures=x.nmixtures, srv_name=x.srv_name, train_size=x.train_size,
gtest_size=x.gtest_size, btest_size=x.btest_size,
window_size=x.window_size, num_clusters=x.num_clusters,
value__gte=0.9).count() > 0:
high_tpr_low_afpr.append(Result2.objects.filter(alg=x.alg,
metric='all_commands', nmixtures=x.nmixtures, srv_name=x.srv_name,
train_size=x.train_size, gtest_size=x.gtest_size, btest_size=x.btest_size,
window_size=x.window_size, num_clusters=x.num_clusters, value__gte=0.9) |
Result2.objects.get(id=x.id))
}}}
and get an error of "AttributeError: 'Result2' object has no attribute
'_known_related_objects'" with the following traceback:
{{{
<ipython-input-88-ab5daa381b14> in <module>()
2 for x in low_afpr_list:
3 if Result2.objects.filter(alg=x.alg, metric='all_commands',
nmixtures=x.nmixtures, srv_name=x.srv_name, train_size=x.train_size,
gtest_size=x.gtest_size, btest_size=x.btest_size,
window_size=x.window_size, num_clusters=x.num_clusters,
value__gte=0.9).count() > 0:
----> 4 high_tpr_low_afpr.append(Result2.objects.filter(alg=x.alg,
metric='all_commands', nmixtures=x.nmixtures, srv_name=x.srv_name,
train_size=x.train_size, gtest_size=x.gtest_size, btest_size=x.btest_size,
window_size=x.window_size, num_clusters=x.num_clusters, value__gte=0.9) |
Result2.objects.get(id=x.id))
/usr/lib/python2.7/site-packages/django/db/models/query.py in __or__(self,
other)
231 if isinstance(other, EmptyQuerySet):
232 return combined
--> 233 combined._merge_known_related_objects(other)
234 combined.query.combine(other.query, sql.OR)
235 return combined
/usr/lib/python2.7/site-packages/django/db/models/query.py in
_merge_known_related_objects(self, other)
955 Keep track of all known related objects from either
QuerySet instance.
956 """
--> 957 for field, objects in
other._known_related_objects.items():
958 self._known_related_objects.setdefault(field,
{}).update(objects)
959
AttributeError: 'Result2' object has no attribute '_known_related_objects'
}}}
If I change my code so that the last line uses filter() instead of get,
ie:
{{{
high_tpr_low_afpr.append(Result2.objects.filter(alg=x.alg,
metric='all_commands', nmixtures=x.nmixtures, srv_name=x.srv_name,
train_size=x.train_size, gtest_size=x.gtest_size, btest_size=x.btest_size,
window_size=x.window_size, num_clusters=x.num_clusters, value__gte=0.9) |
Result2.objects.filter(id=x.id))
}}}
I get the result I was hoping for in the first place.
I assume that concatenating result sets with bitwise or operator should
work regardless of the way the ResultSet object has been created (whether
we used get(), or filter()), hence I started this issue.
Thank you for your attention and keep up the good work!
--
Ticket URL: <https://code.djangoproject.com/ticket/21436>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.f70e2db4ad1a37f4fadfc4a0b47cd17d%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.