Ticket #1109 (new defect)

Opened 2 years ago

Last modified 7 months ago

Modeldesigner throws exception in save_state

Reported by: nyenyec Assigned to: anonymous
Priority: high Milestone: __unclassified__
Component: Toolbox.ModelDesigner Version:
Severity: critical Keywords:
Cc:

Description

Trying to save the model in freshly quickstarted project I got an exception. (See below).

Here's what I did:

  • Installed TurboGears 1.0b1 on Windows
  • Created a project with identity titled "foobar"
  • Changed to the "foobar" directory, started "tg-admin toolbox"
  • Started the model designer
  • Created a class called "Foo"
  • Called "Save Current Session"
  • Looked at the log, saw the exception
2006-09-10 21:01:04,421 turbogears.controllers DEBUG Calling <function save_stat
e at 0x015F0AB0> with *((<turbogears.toolbox.designer.Designer object at 0x015EE
3D0>, u'{"name":"foobar", "models":{"Foo":{"name":"Foo", "parent_class":"SQLObje
ct", "table_name":"", "id_name":"", "columns":{}, "relations":{}}}, "ordered_mod
els":[]}')), **({'name': u'foo'})
10/Sep/2006:21:01:04 HTTP INFO Page handler: <function _wrapper at 0x0170C0F0>
Traceback (most recent call last):
  File "c:\python24\lib\site-packages\CherryPy-2.2.1-py2.4.egg\cherrypy\_cphttpt
ools.py", line 105, in _run
    self.main()
  File "c:\python24\lib\site-packages\CherryPy-2.2.1-py2.4.egg\cherrypy\_cphttpt
ools.py", line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\iden
tity\conditions.py", line 275, in _wrapper
    return fn( *args, **kw )
  File "<string>", line 3, in save_state
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\cont
rollers.py", line 326, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\data
base.py", line 246, in so_rwt
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\cont
rollers.py", line 343, in <lambda>
    mapping, fragment, args, kw)))
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\cont
rollers.py", line 367, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\erro
rhandling.py", line 71, in try_call
    return func(self, *args, **kw)
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\tool
box\designer\__init__.py", line 215, in save_state
    if name != session_file_name: name = self.save_session_as_name(name)
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\tool
box\designer\__init__.py", line 204, in save_session_as_name
    name = name.translate(string.maketrans('',''), string.punctuation)
TypeError: translate() takes exactly one argument (2 given)
Request Headers:
  COOKIE: tg-visit=2b777b57c302f63e302d9a0b20a8a357c648471b
  Content-Length: 175
  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.6) Gecko/
20060728 Firefox/1.5.0.6
  CONNECTION: keep-alive
  PRAGMA: no-cache
  CONTENT-LENGTH: 175
  HOST: localhost:7654
  CACHE-CONTROL: no-cache
  CONTENT-TYPE: application/x-www-form-urlencoded
  ACCEPT: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/pl
ain;q=0.8,image/png,*/*;q=0.5
  Remote-Addr: 127.0.0.1
  ACCEPT-LANGUAGE: en-us,en;q=0.5
  Content-Type: application/x-www-form-urlencoded
  Remote-Host: 127.0.0.1
  ACCEPT-ENCODING: gzip,deflate
  KEEP-ALIVE: 300
127.0.0.1 - - [10/Sep/2006:21:01:04] "POST /designer/save_state HTTP/1.1" 500 27
22 "" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/2006072
8 Firefox/1.5.0.6"

Change History

09/23/06 17:19:13 changed by douglaz

  • severity changed from normal to major.

I got the sample problem. This happens because name is a unicode string, so it don't need a translation table.

09/23/06 18:44:23 changed by jorge.vargas

  • priority changed from normal to high.
  • component changed from Toolbox to Toolbox.ModelDesigner.
  • severity changed from major to critical.
  • milestone changed from 1.0b1 to 1.0b2.

11/15/06 19:00:58 changed by roger.demetrescu

This little patch gets rid of the error, but I am not sure if it is the best solution (eg. if I try to save a session using "áéíóú" as the name, the file created has the name "áéíóú.js"):

Index: turbogears/toolbox/designer/__init__.py
===================================================================
--- turbogears/toolbox/designer/__init__.py	(revision 2077)
+++ turbogears/toolbox/designer/__init__.py	(working copy)
@@ -201,7 +201,7 @@
     load_current_model= turbogears.expose(format='json')(load_current_model)
 
     def save_session_as_name(self,name):
-        name = name.translate(string.maketrans('',''), string.punctuation) 
+        name = name.encode('utf8').translate(string.maketrans('',''), string.punctuation) 
         name =  ''.join([x.title() for x in name.split()]) #camelcase to remove spaces
         sessions_directory = pkg_resources.resource_filename(__name__,os.path.join('static','sessions'))
         postfix = ''

It does apply well if only 'ascii' names are used... :)

01/11/07 14:52:46 changed by alberto

  • milestone changed from 1.0b2 to 1.1.

03/28/07 12:42:02 changed by alberto

  • milestone changed from 1.1 to __unclassified__.

Batch moved into unclassified from 1.1 to properly track progress on the later