CRM-21159 Address fields cause DB errors when adding contacts to group from Search Builder

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Important
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.7.21, 4.7.22, 4.7.23, 4.7.27
    • Fix Version/s: 4.7.31
    • Component/s: CiviCRM Search
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      No

      Description

      "Unknown column" errors occur when the Search Builder is used to create a search that includes an address field (City, State and Country tested so far) from a location type other than Primary, then attempts to add all search results to a group.

      Steps to reproduce:

      1. Create a search using the Search Builder on a CiviCRM 4.7.x site.
      2. Include a State, City, or Country field in the search.
      3. Set the Location Type for that field to anything other than Primary (Home, Billing, Main, Other or Work)
      4. Select all records returned by the search.
      5. Choose "Group - add contacts" from the Actions menu.

      The debug_info from an example of such an error:

      SELECT contact_a.id as contact_id FROM civicrm_contact contact_a WHERE ( ( `Home-address`.state_province_id = '1031' ) ) AND (contact_a.is_deleted = 0) ORDER BY `contact_a`.`sort_name` asc, `contact_a`.`id` [nativecode=1054 ** Unknown column 'Home-address.state_province_id' in 'where clause']
      

      The error doesn't occur if Primary is used as the Location Type, or if the user selects all records displayed on one page of results (no matter how many rows are included) rather than selecting all records.

        Attachments

          Activity

          [CRM-21159] Address fields cause DB errors when adding contacts to group from Search Builder
          Jon K Goldberg added a comment -

          I wasn't able to replicate this on http://dmaster.demo.civicrm.org.  See screenshot.  I wonder if this was fixed as a side effect of CRM-21130?  Please confirm if you're able to replicate this error on one of the sandbox sites.

          Jack Aponte added a comment -

           

          Thanks for the quick response, Jon! I hadn't thought to test this on a sandbox site.

          I was able to replicate this error on dmaster.demo.civicrm.org. Steps I took after logging into the site:

          1. Used the Search Builder (http://dmaster.demo.civicrm.org/civicrm/contact/search/builder?reset=1) to create a search that includes contacts where State (Home) = California.
          2. Clicked the "All 16 records" radio button.
          3. Selected "Group - add contacts" from the Actions menu.

          The "DB Error: no such field" screen appears directly after clicking or selecting "Group - add contacts." 

          Jack Aponte added a comment -

          I replicated your search (City (Work) ≠ 'Brooklyn') and the error did NOT happen when I tried to add those contacts to a group! There weren't any records that matched the search using = instead of ≠ so I couldn't test the converse.

          Further testing reveals that perhaps this isn't actually a problem for the city field, only for the State and Country fields? (I haven't any other address fields yet!)

          • City (Work) = 'Asheville' - no error
          • City (Work) ≠ 'Asheville' - no error
          • State (Work) = North Carolina - error
          • State (Work) ≠ North Carolina - error
          • Country (Work) = United States - error
          • Country (Work) ≠ Tonga - error
          Jack Aponte added a comment -

          Noting here that this problem still exists after updating to CiviCRM 4.7.27; the error occurs in both the Drupal and Backdrop versions.

            People

            • Assignee:
              Unassigned
              Reporter:
              Jack Aponte

              Dates

              • Created:
                Updated:
                Resolved: