Opened 10 years ago

Closed 10 years ago

#9536 closed (worksforme)

sql error (1054, "Unknown column '' in 'on clause'")

Reported by: sergo Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: sql tagging multilingual
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

I'm using django-tagging and django-multilingual applications in my project. I don't know if the problem is in these packages or it is more general. Google gives this , so I thought it is more general problem.

Error page says:


Request Method: GET
Request URL:
Django Version: 1.1 pre-alpha SVN-9285
Python Version: 2.5.2
Installed Applications:
Installed Middleware:

File "C:\Python25\lib\site-packages\django\core\handlers\" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python25\lib\site-packages\tagging\" in tagged_object_list
  52.     return object_list(request, queryset, **kwargs)
File "C:\Python25\lib\site-packages\django\views\generic\" in object_list
  60.             page_obj =
File "C:\Python25\lib\site-packages\django\core\" in page
  37.         number = self.validate_number(number)
File "C:\Python25\lib\site-packages\django\core\" in validate_number
  28.         if number > self.num_pages:
File "C:\Python25\lib\site-packages\django\core\" in _get_num_pages
  60.             if self.count == 0 and not self.allow_empty_first_page:
File "C:\Python25\lib\site-packages\django\core\" in _get_count
  48.                 self._count = self.object_list.count()
File "C:\Python25\lib\site-packages\django\db\models\" in count
  296.         return self.query.get_count()
File "C:\Python25\lib\site-packages\django\db\models\sql\" in get_count
  237.         data = obj.execute_sql(SINGLE)
File "C:\Python25\lib\site-packages\django\db\models\sql\" in execute_sql
  1734.         cursor.execute(sql, params)
File "C:\Python25\lib\site-packages\django\db\backends\" in execute
  19.             return self.cursor.execute(sql, params)
File "C:\Python25\lib\site-packages\django\db\backends\mysql\" in execute
  83.             return self.cursor.execute(query, args)
File "C:\Python25\lib\site-packages\MySQLdb\" in execute
  166.             self.errorhandler(self, exc, value)
File "C:\Python25\lib\site-packages\MySQLdb\" in defaulterrorhandler
  35.     raise errorclass, errorvalue

Exception Type: OperationalError at /scripts/tag/material/
Exception Value: (1054, "Unknown column '' in 'on clause'")

Change History (3)

comment:1 Changed 10 years ago by Ramiro Morales

Description: modified (diff)

(reformatted description)

comment:2 Changed 10 years ago by Karen Tracey

I see you put more info in the issue you filed over at django-multilingual:

specifically the query that causes the error. It is related to that MySQL bug you referenced (which is closed not a bug) -- the problem is that MySQL does not accept a query like this (wrapped for some measure of readability):

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.45-Debian_1ubuntu3.3-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SELECT COUNT(*) FROM `proj_project` , `tagging_taggeditem`
       LEFT JOIN `proj_project_translation` AS `proj_project_translation_en`
       ON ((`proj_project_translation_en`.master_id = `proj_project`.`id`)
       AND (`proj_project_translation_en`.language_id = 1))
       LEFT JOIN `proj_project_translation` AS `proj_project_translation_fr`
       ON ((`proj_project_translation_fr`.master_id = `proj_project`.`id`)
       AND (`proj_project_translation_fr`.language_id = 2))
       WHERE `tagging_taggeditem`.content_type_id = 32
       AND `tagging_taggeditem`.tag_id = 1
       AND `proj_project`.`id` = `tagging_taggeditem`.object_id;
ERROR 1054 (42S22): Unknown column '' in 'on clause'

rather it requires the first tables after the FROM to be enclosed in ():

mysql> SELECT COUNT(*) FROM (`proj_project` , `tagging_taggeditem`)
       LEFT JOIN `proj_project_translation` AS `proj_project_translation_en`
       ON ((`proj_project_translation_en`.master_id = `proj_project`.`id`)
       AND (`proj_project_translation_en`.language_id = 1))
       LEFT JOIN `proj_project_translation` AS `proj_project_translation_fr`
       ON ((`proj_project_translation_fr`.master_id = `proj_project`.`id`)
       AND (`proj_project_translation_fr`.language_id = 2))
       WHERE `tagging_taggeditem`.content_type_id = 32
       AND `tagging_taggeditem`.tag_id = 1
       AND `proj_project`.`id` = `tagging_taggeditem`.object_id;
| COUNT(*) |
|        1 | 
1 row in set (0.00 sec)

I believe it is django-multilingual that is adding all the LEFT JOIN stuff that is causing the problem, based on this note from the MySQL doc referenced in the MySQL bug:

"Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are."

Whether django-multilingual has control wrapping parens around the first tables specified in the query is something I don't know, so I can't say whether this is strictly a django-multilingual problem or a Django one. I also don't know if this is just a MySQL issue or affects other DBs -- I ran into trouble duplicating the setup on a different DB (it appears you cannot create a new tag once you've added django-multilingual into the mix), and I've run out of time to spend on this now. My initial impression is the combo of these two apps is pretty fragile.

comment:3 Changed 10 years ago by sergo

Component: UncategorizedDatabase layer (models, ORM)
Has patch: set
Resolution: worksforme
Status: newclosed

After some debugging I've found the exact place where "FROM proj_project , tagging_taggeditem ..." part is composing.
It is in the django/db/models/sql/ file, get_from_clause(self) function, line 562.

I've changed:
connector = not first and ', ' or
connector = not first and 'JOIN ' or

so "FROM proj_project , tagging_taggeditem" piece became "FROM proj_project JOIN tagging_taggeditem" and tagging started to work.

This patch resolve my particular problem with tagging+multilingual applications, so I don't know if it's a bug in Django, or it fixes somehow tagging/multilingual's problem.

Note: See TracTickets for help on using tickets.
Back to Top