Duplicate entry '1' for key 'PRIMARY'

Discussion in 'ISPConfig 3 Priority Support' started by atle, Oct 24, 2020.

  1. atle

    atle Member HowtoForge Supporter

    When I click on the "Limits" tab for some clients, see
    https://xxa.se/i/205mg0t483mhaj57.png
    I get the error message:

    Code:
    Create Thread: Duplicate entry '1' for key 'PRIMARY'
    Where should I look to find root cause of this? I have checked the table client, and the primary key client_id us unique there, and table client_template is also ok.
     
  2. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Did you update recently and did this issue start after that? If so, how did you update?

    (re-)running the update might help:
    Code:
    cd /tmp
    wget https://www.ispconfig.org/downloads/ISPConfig-3.2.tar.gz
    tar xvfz ISPConfig-3.2.tar.gz
    cd ispconfig3_install/install
    php -q update.php
     
  3. atle

    atle Member HowtoForge Supporter

    Nope, I have not updated since the initial 3.2 version, which was installed from scratch. I will see if the update fixes this, however this problem has started to occur.
     
  4. atle

    atle Member HowtoForge Supporter

    Nope, same error after update.
     
  5. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Which guide did you follow to install your system?
    What is version shown under Help -> Version?
    Have you tried rebooting your system (I don't think this would work but it seems that it has worked for a user a while back)?
     
  6. atle

    atle Member HowtoForge Supporter

    Code:
    ISPConfig Version: 3.2
    I followed the PDF guide, for Debian 10 and ISPConfig 3.1. But, it used to work, for about a week, something has happened today that caused this.
    Reboot did not help.
     
  7. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    So you've gone through the whole table client and client_template? Maybe in the table client_template_assigned? Did you remove a template that was assigned to some clients maybe?

    If I understand correctly only some of your clients have this issue, not all?
     
  8. atle

    atle Member HowtoForge Supporter

    Yes, I went through the whole table client, there are only 5 clients there, I am just evaluating ISPConfig. I have not checked the other tables you mention, I will do that. There is only one template, and that template has not been removed. Not all clients, 3 of 5 have this issue. If you tell me what I should look after int the db I would be grateful.
     
  9. atle

    atle Member HowtoForge Supporter

    table client_template_assigned is empty.
     
  10. atle

    atle Member HowtoForge Supporter

    template_master for this client is set to 1 which corresponds to the only template there is.
     
  11. atle

    atle Member HowtoForge Supporter

    The error occurs at
    Code:
    parent::onSubmit() 
    in function onSubmit() in file client_edit.php
    https://xxa.se/i/wyikq41tekyc17oqk0x.png
    I dont know where to find
    Code:
    parent::onSubmit() 
    to debug this further.
     
  12. Jesse Norell

    Jesse Norell Well-Known Member Staff Member Howtoforge Staff

    A parent comes from php class extension, so go to the top of this file and see what class it extends, then find where that class is defined.
     
    atle likes this.
  13. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Did you change anything on this code? It is not the same as what's in the 3.2. Release, especially this part:
    upload_2020-10-24_19-42-31.png
    try commenting out the line under
    Code:
    if($this->id !=0)
     
  14. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Did you install ISPConfig 3.2 using Perfect Server Guide for 3.1?
     
  15. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    That should not cause any problems except that you're missing GoAccess and some compression packages, I think. And the screenshotted file is incorrect for sure - must have been changed locally. So almost sure that causes it.
     
  16. atle

    atle Member HowtoForge Supporter

    BS. The file has been changed, yes, but with debug code I put there to identify the problem. The problem was of course there before I edited it. Please dont underestimate/patronize me.
    I have however after several of hours debugging identified the root cause.
    The problem occurs in function
    Code:
    protected function _getDatasourceData($field, $record, $api = false)
    in the file tform_base.inc.php
    The function die() is called here:
    Code:
                            // Getting the records
                            $tmp_records = $app->db->queryAllRecords($querystring);
                            if($app->db->errorMessage != '') die($app->db->errorMessage);
                            if(is_array($tmp_records)) {
                                    $key_field = $field["datasource"]["keyfield"];
                                    $value_field = $field["datasource"]["valuefield"];
                                    foreach($tmp_records as $tmp_rec) {
                                            $tmp_id = $tmp_rec[$key_field];
                                            $values[$tmp_id] = $tmp_rec[$value_field];
                                    }
                            }
    
    The query string sent is
    Code:
    SELECT template_id,template_name FROM openvz_template WHERE 1 ORDER BY template_name
    and
    Code:
    $app->db->errorMessage
    returns
    Code:
    'Duplicate entry \'1\' for key \'PRIMARY\''
    If I comment the line
    Code:
    //if($app->db->errorMessage != '') die($app->db->errorMessage);
    the problem disappear.
    When I feed the above SQL query to mysql, commandline as well via phpmyadmin, there is no error. However, since this problem is solved by commenting the line, I dont bother to debug any more.

    Thanks.

    Code:
    root@ic:/usr/local/ispconfig/interface/lib/classes# diff -c tform_base.inc.php-orig tform_base.inc.php
    *** tform_base.inc.php-orig    2020-10-24 14:46:06.966750533 +0200
    --- tform_base.inc.php    2020-10-25 19:42:37.940873974 +0100
    ***************
    *** 280,286 ****
    
                  // Getting the records
                  $tmp_records = $app->db->queryAllRecords($querystring);
    !             if($app->db->errorMessage != '') die($app->db->errorMessage);
                  if(is_array($tmp_records)) {
                      $key_field = $field["datasource"]["keyfield"];
                      $value_field = $field["datasource"]["valuefield"];
    --- 280,286 ----
    
                  // Getting the records
                  $tmp_records = $app->db->queryAllRecords($querystring);
    ! //            if($app->db->errorMessage != '') die($app->db->errorMessage);
                  if(is_array($tmp_records)) {
                      $key_field = $field["datasource"]["keyfield"];
                      $value_field = $field["datasource"]["valuefield"];
     
    Last edited: Oct 25, 2020
  17. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    I don't mean to underestimate / patronize you. But as you can see in https://git.ispconfig.org/ispconfig/ispconfig3/-/blob/develop/interface/web/client/client_edit.php , your file differs from the original. So I told you that something is wrong there, trying to be helpful to you :)
     
  18. atle

    atle Member HowtoForge Supporter

    Yes, and I am trying to be helpful to you.
     
  19. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Yes, thanks for your extensive debugging. I have not seen any reports about this before, but we will have to check it.
     
  20. atle

    atle Member HowtoForge Supporter

    Since there is not problem with the sql query as such I would assume there is some kind of garbage collection issue.
     

Share This Page