MantisBT - TestLink
View Issue Details
0007150TestLinkTest Plan (builds, milestones, test assign)public2015-06-05 13:342015-09-19 08:49
dstraube 
fman 
normalminoralways
closedfixed 
LinuxDebianDebian 7.8
1.9.13 (2015 #1) 
1.9.14 (2015 Q3) 
Postgres
Firefox 38.0.1
PHP 5.4.4-14
READY FOR TESTING
0007150: Copying builds without release date fails (POSTGRES)
Version 1.9.13 has an issue with copying builds that do not have a release date set. It occurs when you try to copy a testplan including the builds and assignments.

Output in event log:
     ERROR ON exec_query() - database.class.php
0 - - /* Class:testplan - Method: copy_builds */ INSERT INTO builds (name,notes,release_date,testplan_id) VALUES ('>18234','','', 50713)
THE MESSAGE : /* Class:testplan - Method: copy_builds */ INSERT INTO builds (name,notes,release_date,testplan_id) VALUES ('>18234','','', 50713) Query failed: errorcode[0] errormsg:

This is new in version 1.9.13, the previous version didn't take release dates into account.
Try to copy a testplan including builds that have no release_date defined.
The error is in /lib/functions/testplan.class.php:

  private function copy_builds($id,$new_tplan_id)
  {
    $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
    $rs=$this->get_builds($id);

    $id_mapping = array();
    if(!is_null($rs))
    {
      foreach($rs as $build)
      {
        $sql = " /* $debugMsg */ INSERT INTO {$this->tables['builds']} " .
               " (name,notes,release_date,testplan_id) " .
               "VALUES ('" . $this->db->prepare_string($build['name']) ."'," .
               "'" . $this->db->prepare_string($build['notes']) . "'," .
               "'" . $this->db->prepare_string($build['release_date']) . "'," .
               " {$new_tplan_id})";

        $this->db->exec_query($sql);
        $new_id = $this->db->insert_id($this->tables['builds']);
        $id_mapping[$build['id']] = $new_id;
      }
    }
    return $id_mapping;
  }

The problem is the line that prepares the release_date string. When the columns is empty it will insert an empty string like this:

INSERT INTO builds (name,notes,release_date,testplan_id) VALUES ('>18234','','', 50713)

The database then complains:
ERROR: invalid input syntax for type date: ""

The column release_date has the type "date", so it should have been a NULL value instead of an empty string.

The table is defined as:
                                       Table "public.builds"
     Column | Type | Modifiers
----------------+-----------------------------+-----------------------------------------------------
 id | bigint | not null default nextval('builds_id_seq'::regclass)
 testplan_id | bigint | not null default (0)::bigint
 name | character varying(100) | not null default 'undefined'::character varying
 notes | text |
 active | smallint | not null default (1)::smallint
 is_open | smallint | not null default (1)::smallint
 author_id | bigint |
 creation_ts | timestamp without time zone | not null default now()
 release_date | date |
 closed_on_date | date |


No tags attached.
child of 0006830closed fman Availables hot-fixes for 1.9.13 & How To get full fixed package from GitHub 
Issue History
2015-06-05 13:34dstraubeNew Issue
2015-06-05 17:13fmanNote Added: 0023443
2015-06-07 08:10fmanNote Added: 0023444
2015-06-07 08:11fmanQA Team - Task Workflow Status => TBD
2015-06-07 08:11fmanFixed in Version => 1.9.14 (2015 Q3)
2015-06-07 08:11fmanDescription Updatedbug_revision_view_page.php?rev_id=4457#r4457
2015-06-07 08:11fmanAssigned To => fman
2015-06-07 08:11fmanStatusnew => feedback
2015-06-07 08:11fmanRelationship addedchild of 0006830
2015-06-08 08:51dstraubeNote Added: 0023447
2015-06-08 08:51dstraubeStatusfeedback => assigned
2015-06-08 09:05fmanNote Added: 0023448
2015-06-08 09:06fmanSummaryCopying builds without release date fails => Copying builds without release date fails (POSTGRES)
2015-06-08 21:09fmanQA Team - Task Workflow StatusTBD => READY FOR TESTING
2015-06-08 21:09fmanNote Added: 0023455
2015-06-08 21:09fmanStatusassigned => resolved
2015-06-08 21:09fmanResolutionopen => fixed
2015-06-09 06:42dstraubeNote Added: 0023457
2015-06-09 08:54fmanNote Added: 0023459
2015-06-09 09:05dstraubeNote Added: 0023460
2015-09-19 08:49fmanNote Added: 0023927
2015-09-19 08:49fmanStatusresolved => closed

Notes
(0023443)
fman   
2015-06-05 17:13   
thanks for help
(0023444)
fman   
2015-06-07 08:10   
Tested with latest code from github
1) Create Test Project VERA (EMPTY no test suites, no test cases)
2) Create Test Project PA (Empty)
3) Create build 10 on Test Project PA, leave release date EMPTY
4) Create Test Project PB as copy of PA

No issue
(0023447)
dstraube   
2015-06-08 08:51   
Sorry, I should have provided more details about the way to reproduce the issue. It happens when you create a new testplan and create it from an existing one that has builds without release date attached to it.

I've checked this again with the latest code base. Problem still exists.

Here are the steps I did with a fresh installation using a POSTGRES database.

1) Create Test Project Testproject (EMPTY no test suites, no test cases)
2) Create Test Plan TP1
3) Select Test Plan TP1 and create a new Build for it, leave "Release date" field empty (default).
4) Go to Test Plan Management and create a new Test Plan
5) Enter TP2 as Name
6) Create from existing Test Plan: Choose TP1, leave everything else to default values.
7) Save and watch the error messages:

 ==============================================================================

 DB Access Error - debug_print_backtrace() OUTPUT START

 ATTENTION: Enabling more debug info will produce path disclosure weakness (CWE-200)

            Having this additional Information could be useful for reporting

            issue to development TEAM.

 ==============================================================================

 ==============================================================================

 ==============================================================================

 DB Access Error - debug_print_backtrace() OUTPUT START

 ATTENTION: Enabling more debug info will produce path disclosure weakness (CWE-200)

            Having this additional Information could be useful for reporting

            issue to development TEAM.

 ==============================================================================

 ==============================================================================
(0023448)
fman   
2015-06-08 09:05   
OK, thanks, now I've got is postgres, and I've tested using MySQL
I'm going to check on following days
(0023455)
fman   
2015-06-08 21:09   
https://github.com/TestLinkOpenSourceTRMS/testlink-code/commit/e049b0608837270f9740a749ec0a439f26bd2f72 [^]
(0023457)
dstraube   
2015-06-09 06:42   
Do you want that "echo $sql;" in line 1495 really in there?
(0023459)
fman   
2015-06-09 08:54   
NO just a mistake.
Important thing is to know if is fixed
(0023460)
dstraube   
2015-06-09 09:05   
I've looked at the code and it will solve the problem. I've then tested it and it works fine. Both cases now work, for builds with release date and for those without.

Thank you for the fast fix.
(0023927)
fman   
2015-09-19 08:49   
1.9.14 Padawan - released - 2015-09-19