Opened 18 years ago
Closed 18 years ago
#7095 closed (fixed)
Error with Many2Many filter() in models managers after queryset-refactor merge
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Hi,
first of all, thank you all for your excellent work; after the qs-rf branch merge, there is a small regression that cause a python error in where.py during an update() if a custom Manager tries to .filter() thru a ManyToManyField in get_query_set().
This breaks, for example, CurrentSiteManager with a M2M 'site' field.
So, if you have a model like:
from django.db import models
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager
class Dummy(models.Model):
dumb = models.TextField()
site = models.ManyToManyField(Site)
objects = CurrentSiteManager()
def dummy_view(request):
t = Dummy.objects.create(dumb='abc')
t.site.add(settings.SITE_ID)
t.save()
t.save() would give a TypeError: object of type 'Query' has no len().
At some point, a Query object get passed to make_atom rather than a list.
This is the traceback:
Traceback:
File "D:\Arturo\django\core\handlers\base.py" in get_response
82. response = callback(request, *callback_args, **callback_kwargs)
File "D:\Arturo\arturo5\magazine\views_manager_article.py" in article_add
45. t.save()
File "D:\Arturo\django\db\models\base.py" in save
298. self.save_base()
File "D:\Arturo\django\db\models\base.py" in save_base
338. manager.filter(pk=pk_val)._update(values)
File "D:\Arturo\django\db\models\query.py" in _update
299. query.execute_sql(None)
File "D:\Arturo\django\db\models\sql\subqueries.py" in execute_sql
112. super(UpdateQuery, self).execute_sql(result_type)
File "D:\Arturo\django\db\models\sql\query.py" in execute_sql
1432. sql, params = self.as_sql()
File "D:\Arturo\django\db\models\sql\subqueries.py" in as_sql
136. where, params = self.where.as_sql()
File "D:\Arturo\django\db\models\sql\where.py" in as_sql
61. sql, params = self.make_atom(child, qn)
File "D:\Arturo\django\db\models\sql\where.py" in make_atom
130. return ('%s IN (%s)' % (field_sql, ', '.join(['%s'] * len(value))),
Exception Type: TypeError at /arturo/magazine/add/
Exception Value: object of type 'Query' has no len()
Change History (4)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
The above commit fixes the problem for SQLite and PostgreSQL. Unfortunately, it reveals another bug that affects MySQL users because of MySQL's non-standard UPDATE syntax rules. Working on that piece of the puzzle now.
comment:3 by , 18 years ago
comment:4 by , 18 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
(In [7494]) Allow Query objects to be values in query filters. This already existed for
relations, but not for normal fields. The latter comes up naturally in some
update statements.
Refs #7095