El Domingo 16 Julio 2006 11:59, Christopher Arndt escribió:

CA> Well, if you want us to help with your code, you gotta post the real
CA> thing! Or test your example code properly ;-)
the code is:

first the model

class Especialidad(SQLObject):
  nombre = UnicodeCol(alternateID=True)

now the controller:

  @tg.expose(format="json")
  def saveEspecialidad(self,especialidad):
    try:
      esp=m.Especialidad(nombre=especialidad)
    except Exception: 
      return dict(tg_errors=u"La especialidad ya existe") 

    return dict(id=esp.id,nombre=esp.nombre)


and now the javascript stuff:

//this one simply reads the data, sets the callback, and calls the controller
// saveEspecialidad (above)
function addEspecialidad() {
  var esp = prompt("AƱadir especialidad","Especialidad");
  if (esp==null) {
    return;
  }
  d=loadJSONDoc("./saveEspecialidad",{tg_format:"json",especialidad:esp});
  d.addCallback(clbAddEspecialidad);
}

//this one updates the dom tree
function clbAddEspecialidad (d) {
  if (d["tg_errors"]) {
    alert(d["tg_errors"]);
    return;
  } 
  select = document.getElementsByName("especialidad")[0];
  appendChildNodes(select, OPTION({"value":d["id"]},d["nombre"]));
}


Now, the problem is that when I try to insert an already existing value:

- the controller (saveEspecialidad) is called and the exception is raised. The 
exception says: 'duplicate key violates unique constraint 
"especialidad_nombre_key'

- in the callback function (clbAddEspecialidad) I get the proper alert message
(alert(d["tg_errors"]);)

- after that, any attempt of inserting a new speciality (name) doesn't call 
the callback function not the controller

- besides, any attempt of reload the page fails, the browser waits, and waits, 
and waits.... 

- any attempt of going to other urls of my web app fail (say, go to /, or any 
other page)

- when I kill the server (Crtl+C), it keeps alive, and with some other 
processes. THe following is an (edited) output of "ps ax"
3320 pts/0    S      0:01 /usr/bin/python start-siterapias.py (four more of 
this)
3325 ?        S      0:00 postgres: postgres terapias 127.0.0.1(32780) idle 
(terapias is my database name)
3326 ?        S      0:00 postgres: postgres terapias 127.0.0.1(32781) idle in 
transaction

as you can see, my db engine is postgres, it is v. 8.1.4

despite of my code being here, I get the same problem when using catwalk: when 
I try to add a (duplicate) value to the table "Especialidad" using it, the 
same thing happens: the browser can't reload the page and the server 
(tg-admin toolbox) keeps alive after killing it with Ctrl+C. 

I have tested it too with other project -the fasttrack project of Jonatan 
LaCour- inserting a duplicate value, and the same behaviour arises.

It is not only related to the duplicates insertion, but instead (I think) with 
the handling of database-related exceptions, because it was happening too 
when I tried to insert unicode values in string cols (that was my original 
problem)

Thanks a lot for your help and patience
-- 
Javier Rojas

GPG key:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xA1C57061

Attachment: pgpf5fkzDasB3.pgp
Description: PGP signature

Reply via email to