#701: [PATCH][TEST] catwalk.Browse.join_foreign_key makes bad SQLObject column
name from joinColumn
-------------------------------------+--------------------------------------
 Reporter:  [email protected]  |        Owner:         
     Type:  defect                   |       Status:  new    
 Priority:  high                     |    Milestone:  1.x    
Component:  Toolbox.Catwalk          |      Version:  1.0.4b1
 Severity:  major                    |   Resolution:         
 Keywords:                           |  
-------------------------------------+--------------------------------------
Changes (by jorge.vargas):

  * milestone:  __unclassified__ => 1.x

Old description:

> Just after upgrade from 0.9a1 to 0.9a2...
>
> In catwalk.Browse.join_foreign_key
> (turbogears/toolbox/catwalk/browse.py:190), a SQLObject.SORelatedJoin
> column is passed in, and join_foreign_key needs to determine the
> SQLObject column name of the foreign key in the  SQLObject that this
> column refers to. However, the SORelatedJoin column only has the database
> version of the foreign key column name, and attempts to reconstruct the
> SQLObject name of the column as follows:
>
>    foreign_key = "%sID"%column.joinColumn.split('_')[0]
>
> which is bad in many ways, but in particular, suppose the SQL column name
> is a ForeignKey multiWordIdentifier, then the database column name is
> multi_word_identifier_id, but this hack generates "multiID" and an
> exception ensues.
>
> Current (very bad) patch is to ask the other table for all of its columns
> to see which one matches the .joinColumn string and use its name.
>
> foreign_key = [ cl.name for cl in column.otherClass.sqlmeta.columnList if
> cl.dbName == column.joinColumn ][0]
>
> Very ugly. However, I don't see any other facility for reverse mapping
> dbName to name.
>
> nathan
>
> model.py:
>
> class PeptideMapping(SQLObject):
>   codingSequence = ForeignKey('CodingSequence')
>
> class CodingSequence(SQLObject):
>   peptideMapping = RelatedJoin('PeptideMapping')
>
> Exception:
>
> 31/Mar/2006:11:03:37 HTTP INFO Page handler: <bound method Browse.index
> of <turbogears.toolbox.catwalk.browse.Browse object at 0xb6cb1e0c>>
> Traceback (most recent call last):
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 99,
> in _run
>     self.main()
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 248,
> in main
>     body = page_handler(*virtual_path, **self.params)
>   File "<string>", line 3, in index
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 207,
> in expose
>     output = database.run_with_transaction(expose._expose,func, accept,
> allow_json, allow_json_from_config,*args, **kw)
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/database.py", line 216, in
> run_with_transaction
>     retval = func(*args, **kw)
>   File "<string>", line 5, in _expose
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 228,
> in <lambda>
>     expose._expose.when(rule)(lambda _func, accept, allow_json,
> allow_json_from_config,*args,**kw: _execute_func(
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 246,
> in _execute_func
>     output = errorhandling.try_call(func, *args, **kw)
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/errorhandling.py", line
> 59, in try_call
>     output = func(self, *args, **kw)
>   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> line 20, in index
>     total,rows = self.rows_for_model(object_name,start,page_size,filters)
>   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> line 119, in rows_for_model
>     relations = self.relation_values(object_name,rows)
>   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> line 138, in relation_values
>     where=AND(
>   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
> packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
> line 195, in join_foreign_key
>     return getattr(column.otherClass.q,foreign_key)
>   File "/fs/hpcbioprojects/python/lib/python2.4/site-
> packages/SQLObject-0.7.1dev_r1457-py2.4.egg/sqlobject/sqlbuilder.py",
> line 362, in __getattr__
>     self.soClass.sqlmeta.columns[attr].dbName,
> KeyError: 'codingID'
> Request Headers:
>   COOKIE: tg-visit=1e956a910599a39aac022a574d7591f2b7e20cf5
>   Content-Length:
>   ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>   USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1)
> Gecko/20060111 Firefox/1.5.0.1
>   CONNECTION: keep-alive
>   HOST: codon.umiacs.umd.edu:8888
>   ACCEPT:
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
>   Remote-Addr: 128.8.141.94
>   ACCEPT-LANGUAGE: en-us,en;q=0.5
>   Content-Type:
>   Remote-Host: 128.8.141.94
>   ACCEPT-ENCODING: gzip,deflate
>   KEEP-ALIVE: 300
> 128.8.141.94 - - [31/Mar/2006:11:03:37] "GET
> /catwalk/browse/?object_name=CodingSequence HTTP/1.1" 500 3535

New description:

 Just after upgrade from 0.9a1 to 0.9a2...
 {{{
 In catwalk.Browse.join_foreign_key
 (turbogears/toolbox/catwalk/browse.py:190), a SQLObject.SORelatedJoin
 column is passed in, and join_foreign_key needs to determine the SQLObject
 column name of the foreign key in the  SQLObject that this column refers
 to. However, the SORelatedJoin column only has the database version of the
 foreign key column name, and attempts to reconstruct the SQLObject name of
 the column as follows:

    foreign_key = "%sID"%column.joinColumn.split('_')[0]

 which is bad in many ways, but in particular, suppose the SQL column name
 is a ForeignKey multiWordIdentifier, then the database column name is
 multi_word_identifier_id, but this hack generates "multiID" and an
 exception ensues.

 Current (very bad) patch is to ask the other table for all of its columns
 to see which one matches the .joinColumn string and use its name.

 foreign_key = [ cl.name for cl in column.otherClass.sqlmeta.columnList if
 cl.dbName == column.joinColumn ][0]

 Very ugly. However, I don't see any other facility for reverse mapping
 dbName to name.

 nathan

 model.py:

 class PeptideMapping(SQLObject):
   codingSequence = ForeignKey('CodingSequence')

 class CodingSequence(SQLObject):
   peptideMapping = RelatedJoin('PeptideMapping')

 Exception:

 31/Mar/2006:11:03:37 HTTP INFO Page handler: <bound method Browse.index of
 <turbogears.toolbox.catwalk.browse.Browse object at 0xb6cb1e0c>>
 Traceback (most recent call last):
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 99,
 in _run
     self.main()
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/CherryPy-2.2.0rc1-py2.4.egg/cherrypy/_cphttptools.py", line 248,
 in main
     body = page_handler(*virtual_path, **self.params)
   File "<string>", line 3, in index
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 207,
 in expose
     output = database.run_with_transaction(expose._expose,func, accept,
 allow_json, allow_json_from_config,*args, **kw)
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/database.py", line 216, in
 run_with_transaction
     retval = func(*args, **kw)
   File "<string>", line 5, in _expose
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 228,
 in <lambda>
     expose._expose.when(rule)(lambda _func, accept, allow_json,
 allow_json_from_config,*args,**kw: _execute_func(
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/controllers.py", line 246,
 in _execute_func
     output = errorhandling.try_call(func, *args, **kw)
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/errorhandling.py", line 59,
 in try_call
     output = func(self, *args, **kw)
   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
 line 20, in index
     total,rows = self.rows_for_model(object_name,start,page_size,filters)
   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
 line 119, in rows_for_model
     relations = self.relation_values(object_name,rows)
   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
 line 138, in relation_values
     where=AND(
   File "/fs/hpcbiohomes/nedwards/projects/python/lib/python2.4/site-
 packages/TurboGears-0.9a2-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
 line 195, in join_foreign_key
     return getattr(column.otherClass.q,foreign_key)
   File "/fs/hpcbioprojects/python/lib/python2.4/site-
 packages/SQLObject-0.7.1dev_r1457-py2.4.egg/sqlobject/sqlbuilder.py", line
 362, in __getattr__
     self.soClass.sqlmeta.columns[attr].dbName,
 KeyError: 'codingID'
 Request Headers:
   COOKIE: tg-visit=1e956a910599a39aac022a574d7591f2b7e20cf5
   Content-Length:
   ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
   USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1)
 Gecko/20060111 Firefox/1.5.0.1
   CONNECTION: keep-alive
   HOST: codon.umiacs.umd.edu:8888
   ACCEPT:
 
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
   Remote-Addr: 128.8.141.94
   ACCEPT-LANGUAGE: en-us,en;q=0.5
   Content-Type:
   Remote-Host: 128.8.141.94
   ACCEPT-ENCODING: gzip,deflate
   KEEP-ALIVE: 300
 128.8.141.94 - - [31/Mar/2006:11:03:37] "GET
 /catwalk/browse/?object_name=CodingSequence HTTP/1.1" 500 3535
 }}}

-- 
Ticket URL: <http://trac.turbogears.org/ticket/701#comment:13>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to