Hi!



For the following code on my controller (auto-wrapped in a transaction by a
decorator in a TurboGears project):

================================================================================
    def update(self, **kwargs):
        usuario = identity.current.user
        agora = datetime.now()
        tipo_ferramenta = model.TipoFerramenta.get(kwargs['id'])
        tipo_ferramenta.set(
            descricao = kwargs['descricao'],
            alteradoPor = usuario,
            alteradoEm = agora,
        )
================================================================================

I get the following output at my auditing trigger on PostgreSQL:

================================================================================
  4 | equipamentos.ferramentas_tipos  | UPDATE   | {'incluido_em': '2007-03-19
  17:49:17', 'alterado_por_id': 1, 'incluido_por_id': 1, 'alterado_em':
  '2007-03-19 17:49:17', 'id': 6, 'descricao': 'Lixa'}                  |
  {'incluido_em': '2007-03-19 17:49:17', 'alterado_por_id': 1,
  'incluido_por_id': 1, 'alterado_em': '2007-03-19 17:49:17', 'id': 6,
  'descricao': 'Lixa'}                  | 2007-03-19 17:53:02.579166 | godoy

  5 | equipamentos.ferramentas_tipos  | UPDATE   | {'incluido_em': '2007-03-19
  17:49:17', 'alterado_por_id': 1, 'incluido_por_id': 1, 'alterado_em':
  '2007-03-19 17:49:17', 'id': 6, 'descricao': 'Lixa'}                  |
  {'incluido_em': '2007-03-19 17:49:17', 'alterado_por_id': 1,
  'incluido_por_id': 1, 'alterado_em': '2007-03-19 17:53:02', 'id': 6,
  'descricao': 'Lixa de Unha'}          | 2007-03-19 17:53:02.579166 | godoy
================================================================================

As you can see by the time -- up to microseconds -- there are two UPDATE
instructions being run on the same transaction.

I've just changed the value of 'descricao' from 'Lixa' to 'Lixa de Unha'
(bogus values, this was a test for the auditing trigger).


I'm sure this is not a failure in the trigger...  Anyhow, here it is the
trigger creation statement:

================================================================================
create trigger t_999_aiud_tipos_ferramentas after insert or update or delete
ON equipamentos.ferramentas_tipos FOR EACH ROW EXECUTE PROCEDURE
auditorias.taiud_auditoria ();
================================================================================


If I run the update command by hand there's only one entry on the table.  SQL
Object's behavior is correct for INSERTs and DELETEs, being the double entry
there just on UPDATEs.


The above class is declared as:

================================================================================
class TipoFerramenta(SQLObject):
    class sqlmeta:
        table = 'equipamentos.ferramentas_tipos'
        registry = 'equipamentos'
        defaultOrder = 'descricao'

    descricao = UnicodeCol(notNone=True)

    # Auditing
    incluidoPor = ForeignKey('Usuario', notNone=True, cascade=False)
    incluidoEm = DateTimeCol(default=datetime.now())
    alteradoPor = ForeignKey('Usuario', notNone=True, cascade=False)
    alteradoEm = DateTimeCol(default=datetime.now())
================================================================================


Any hints on what might be going wrong on my code?  Is anybody else seeing
double UPDATEs using PostgreSQL and psycopg2?

-- 
Jorge Godoy      <[EMAIL PROTECTED]>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to