arcpy/update-hosted-feature-service

FindItem function will match service name with another service name if it is a substring

Closed this issue · 1 comments

We have found that if you have a service called ACME Map Service and run this, it will not check for an exact match and could pick up services with that as a substring.

For Example...

When findItem is called and looks for service name ACME Map Service it will also find...

Alternative ACME Map Service and ACME Map Service Backup in the results array. We found that the results order can change as people manually update/replace the service.

As the code only pulls the id at index 0 out without testing for a match it can pull out the id for wrong service and overwrite the wrong one.

We have modified the findItem function as follows to fix this:

def findItem(self, findType):
        #
        # Find the itemID of whats being updated
        #        
        searchURL = self.http + "/search"
        #print("--Search URL: " + searchURL)

        query_dict = {'f': 'json',
                      'token': self.token,
                      'q': 'title:\"'+ self.serviceName + '\" AND owner:\"' + self.username + '\" AND type:\"' + findType + '\"'}    

        #searchURLwithParams = searchURL + '?' + urllib.urlencode(query_dict)
        #resp = requests.get(searchURLwithParams)

        #jsonResponse = resp.json()

        jsonResponse = sendAGOLReq(searchURL, query_dict)

        if jsonResponse['total'] == 0:
            print "\nCould not find a service to update. Check the service name in the settings.ini"
            logging.info('*********** Failed - Could not find service to update ************************')
            sys.exit()
        else:
            ############### FIXED CODE #########################
            resultList = jsonResponse['results']
            #filter for correct service name... this could probably be written better!
            for it in resultList:
                itemTitle = it["title"]
                if itemTitle == self.serviceName:
                    print("found {} : {}").format(findType, it["id"])
                    return it["id"]
                else:
                    pass
           ############## END FIX #############################

I have seen this is a fork from khibma so I have raise the issue there... https://github.com/khibma/update-hosted-feature-service/issues/12