Modify

Opened 8 days ago

Last modified 8 days ago

#13038 new defect

ValuePropagationPlugin [patch] fix "AttributeError: 'Environment' object has no attribute 'get_db_cnx'"

Reported by: komar Owned by: ChrisNelson
Priority: normal Component: ValuePropagationPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.2

Description

After upgrading trac to 1.2 I get error:

AttributeError: 'Environment' object has no attribute 'get_db_cnx'

there is a patch

--- a/valuepropagation.py	2017-01-05 13:38:50.379971566 +0100
+++ b/valuepropagation.py	2017-01-05 15:03:44.000000000 +0100
@@ -99,13 +99,13 @@
         self.enums = {}
         self.enums['priority_value'] = 'priority'
 
-        db = self.env.get_db_cnx()
-        cursor = db.cursor()
-        cursor.execute("SELECT name," +
-                       db.cast('value', 'int') +
-                       " FROM enum WHERE type=%s", ('priority',))
-        for name, value in cursor:
-            self.p_values[name] = value
+        with self.env.db_query as db:
+            cursor = db.cursor()
+            cursor.execute("SELECT name," +
+                           db.cast('value', 'int') +
+                           " FROM enum WHERE type=%s", ('priority',))
+            for name, value in cursor:
+                self.p_values[name] = value
 
         # ============================================================
         # A propagation method is called from a ticket change listener
@@ -260,11 +260,11 @@
         if q == None:
             self.env.log.debug("%s has no query configured" % r)
         else:
-            db = self.env.get_db_cnx()
-            cursor = db.cursor()
-            cursor.execute(q, (ticket.id,))
-            for id in [int(row[0]) for row in cursor]:
-                self._propagate(r, ticket, old_values, id, id)
+            with self.env.db_query as db:
+                cursor = db.cursor()
+                cursor.execute(q, (ticket.id,))
+                for id in [int(row[0]) for row in cursor]:
+                    self._propagate(r, ticket, old_values, id, id)
 
 
     # Propagate values from ticket to the ticket whose ID is
@@ -323,15 +323,15 @@
                 # Determine sequence number.
                 cnum = 0
                 tm = TicketModule(self.env)
-                db = self.env.get_db_cnx()
-                for change in tm.grouped_changelog_entries(ticket, db):
-                    # FIXME - should this say "and change['cnum'] > cnum?
-                    if change['permanent']:
-                        cnum = change['cnum']
-                # FIXME - Put something in the message?
-                # FIXME - the ticket_changed method gets an author, should
-                # this say "value propagation on behalf of <author>"?
-                ticket.save_changes('value propagation', '', when, db, cnum+1)
+                with self.env.db_query as db:
+                    for change in tm.grouped_changelog_entries(ticket, db):
+                        # FIXME - should this say "and change['cnum'] > cnum?
+                        if change['permanent']:
+                            cnum = change['cnum']
+                    # FIXME - Put something in the message?
+                    # FIXME - the ticket_changed method gets an author, should
+                    # this say "value propagation on behalf of <author>"?
+                    ticket.save_changes('value propagation', '', when, db, cnum+1)
 
             # All the propagation is done, save the new values
             when = datetime.datetime.now()

Attachments (0)

Change History (2)

comment:1 Changed 8 days ago by jun66j5

  • Trac Release set to 1.2

comment:2 Changed 8 days ago by jun66j5

db parameter has been removed from TicketModule.grouped_changelog_entries() and Ticket.save_changes() in trac:r12826. I believe suggested patch is incomplete.

Last edited 8 days ago by jun66j5 (previous) (diff)

Add Comment

Modify Ticket

Action
as new The owner will remain ChrisNelson.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.