Modify

Opened 8 years ago

Closed 8 years ago

#13038 closed defect (fixed)

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

Reported by: komar Owned by: Ryan J Ollos
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 (4)

comment:1 Changed 8 years ago by Jun Omae

Trac Release: 1.2

comment:2 Changed 8 years ago by Jun Omae

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 years ago by Jun Omae (previous) (diff)

comment:3 Changed 8 years ago by Ryan J Ollos

Owner: changed from Chris Nelson to Ryan J Ollos
Status: newaccepted

comment:4 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 16190:

1.2.0dev: Adapt to Trac 1.2 API

  • Fix variable referenced before assigned, fixes #12084
  • Fix attribute error due to int cnum, fixes #11033

Fixes #13038.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.