Ticket #3102 (new defect)

Opened 6 months ago

Last modified 1 month ago

burndown_job.py fails INSERT NULL id

Reported by: anonymous Assigned to: daan
Priority: normal Component: ScrumBurndownPlugin
Severity: critical Keywords: INSERT NULL id in burndown table
Cc: benoitg@coeus.ca Trac Release: 0.11

Description

According to the definition of the burndown table, the id field cannot be null. Yet if burndown_job.py is run with an empty table, it attempts to INSERT a NULL for the id.

--- EXAMPLE ERROR ----

# python burndown_job.py /home/trac/client first run of burndown_job.py today - insert needed Traceback (most recent call last):

File "burndown_job.py", line 82, in ?

main()

File "burndown_job.py", line 76, in main

cursor.execute("INSERT INTO burndown(id,component_name, milestone_name, date, hours_remaining) "\

File "/usr/lib/python2.4/site-packages/Trac-0.11b1-py2.4.egg/trac/db/util.py", line 51, in execute

return self.cursor.execute(sql)

File "/usr/lib/python2.4/site-packages/Trac-0.11b1-py2.4.egg/trac/db/util.py", line 51, in execute

return self.cursor.execute(sql)

File "/usr/lib/python2.4/site-packages/pyPgSQL/PgSQL.py", line 3111, in execute

raise OperationalError, msg

libpq.OperationalError: ERROR: null value in column "id" violates not-null constraint

--- END EXAMPLE ERROR ---

--- CODE REFERENCE ---

burndown.py:69

sqlBurndownCreate = "CREATE TABLE burndown (" \

" id integer PRIMARY KEY NOT NULL,"\ " component_name text NOT NULL,"\ " milestone_name text NOT NULL," \ " date text,"\ " week text,"\ " year text,"\ " hours_remaining integer NOT NULL"\ ")"

burndown_job.py:73

cursor.execute("INSERT INTO burndown(id,component_name, milestone_name, date, hours_remaining) "\

" VALUES(NULL,'%s','%s','%s',%f)" % (comp[0], mile[0], today, hours))

--- END CODE REFERENCE ---

Attachments

patch_null_and_integer.svndiff (3.4 kB) - added by benoitg on 06/19/08 17:02:36.
Patch for #3102

Change History

05/29/08 15:43:24 changed by anonymous

Possible Patch:

create sequence burndown_id_seq;
alter table burndown alter column id set default nextval('burndown_id_seq');


--- old/burndown/burndown_job.py        2006-10-16 12:20:46.000000000 -0700
+++ new/burndown/burndown_job.py        2008-05-29 13:05:57.000000000 -0700
@@ -73,8 +73,8 @@
                     cursor.execute("UPDATE burndown SET hours_remaining = '%f' WHERE date = '%s' AND milestone_name = '%s'"\
                                         "AND component_name = '%s'" % (hours, today, mile[0], comp[0]))
                 else:
-                    cursor.execute("INSERT INTO burndown(id,component_name, milestone_name, date, hours_remaining) "\
-                                        "    VALUES(NULL,'%s','%s','%s',%f)" % (comp[0], mile[0], today, hours))
+                    cursor.execute("INSERT INTO burndown(component_name, milestone_name, date, hours_remaining) "\
+                                        "    VALUES('%s','%s','%s',%f)" % (comp[0], mile[0], today, hours))

     db.commit()

06/09/08 18:10:53 changed by anonymous

The same error is in burndown.py line 330. The id field cannot be null. The fix is the same as above.

In the UPDATE, hours_remaining is an integer field in the database, but here it is being set to a floating point.

I used

alter table burndown alter column hours_remaining type numeric(4,2);

to change the database field so it would accept a floaing value.

06/19/08 14:46:06 changed by anonymous

  • cc set to benoitg@coeus.ca.

06/19/08 17:02:36 changed by benoitg

  • attachment patch_null_and_integer.svndiff added.

Patch for #3102

06/19/08 17:03:11 changed by benoitg

  • severity changed from normal to critical.

I attached a SVN diff fixing both problems. Note that I used float, and the numeric restricted to the range above caused problems. I didn't test schema upgrade, only creation.

10/17/08 01:49:23 changed by daan

  • owner changed from sambloomquist to daan.

11/02/08 11:08:45 changed by daan

Which database is used? Is this tested for MySQL?

11/02/08 15:31:51 changed by benoitg

I tested on postgres


Add/Change #3102 (burndown_job.py fails INSERT NULL id)




Change Properties
Action