Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

TypeError: can only concatenate list (not "NoneType") to list #182

Closed gaolig closed 8 years ago

gaolig commented 8 years ago

I am receiving the subject error when running the sample "adds_rows_to_service.py". The error occurs after most of the rows are added to the service:

error in function: AddFeaturesToFeatureLayer error on line: line 381 error in file name: C:\Python27\ArcGIS10.3\lib\site-packages\arcresthelper\featureservicetools.py with error message: TypeError: can only concatenate list (not "NoneType") to list

I have tried with a couple different feature services and get the same results. The services have around 8,000 records with ~30 fields.

The code is below, which is the same as the sample except for the variables. I have also tried various chunk sizes.

Thanks in advance for any help!

import arcrest
from arcresthelper import featureservicetools
from arcresthelper import common

def trace():
    """
        trace finds the line, the filename
        and error message and returns it
        to the user
    """
    import traceback, inspect,sys
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    filename = inspect.getfile(inspect.currentframe())
    # script name + line number
    line = tbinfo.split(", ")[1]
    # Get Python syntax error
    #
    synerror = traceback.format_exc().splitlines()[-1]
    return line, filename, synerror

def main():
    proxy_port = None
    proxy_url = None

    securityinfo = {}
    securityinfo['security_type'] = 'ArcGIS'#LDAP, NTLM, OAuth, Portal, PKI
    securityinfo['username'] = "UserName"#<UserName>
    securityinfo['password'] = "Password"#<Password>
    securityinfo['org_url'] = "http://www.arcgis.com"
    securityinfo['proxy_url'] = proxy_url
    securityinfo['proxy_port'] = proxy_port
    securityinfo['referer_url'] = None
    securityinfo['token_url'] = None
    securityinfo['certificatefile'] = None
    securityinfo['keyfile'] = None
    securityinfo['client_id'] = None
    securityinfo['secret_id'] = None

    itemId = "1b1012939a2e47fc99cab839393f825a"#<Item ID>

    layerName = "Signs" #layer1
    pathToFeatureClass = r"E:\Temp.gdb\Signs"
    try:

        fst = featureservicetools.featureservicetools(securityinfo)
        if fst.valid == False:
            print fst.message
        else:

            fs = fst.GetFeatureService(itemId=itemId,returnURLOnly=False)
            if not fs is None:

                fs_url = fst.GetLayerFromFeatureService(fs=fs,layerName=layerName,returnURLOnly=True)
                if not fs_url is None:
                    results =  fst.AddFeaturesToFeatureLayer(url=fs_url, pathToFeatureClass=pathToFeatureClass,
                                                      chunksize=2000)
                    if 'addResults' in results:
                        print "%s features added" % len(results['addResults'])
    except (common.ArcRestHelperError),e:
        print "error in function: %s" % e[0]['function']
        print "error on line: %s" % e[0]['line']
        print "error in file name: %s" % e[0]['filename']
        print "with error message: %s" % e[0]['synerror']
        if 'arcpyError' in e[0]:
            print "with arcpy message: %s" % e[0]['arcpyError']

    except:
        line, filename, synerror = trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror

if __name__ == "__main__":
    main()
gaolig commented 8 years ago

I have been able to determine that this is being caused by null geometry. Running the "Repair Geometry" GP Tool appears to fix the issue.

However, our data resides in SDE, and the Repair Geometry tool does not work with SDE data. I ended up exporting the data from SDE to a file GDB, running the Repair Geometry tool, and then re-importing the data back into SDE.

Since this isn't an issue with the code, my only suggestion/thought would be to provide better output on the returned error message. Hopefully, at least, this post is helpful to others who encounter the same problem.

MikeMillerGIS commented 8 years ago

Can you send me a copy of the bad data so I can test and trap the issue? Mmiller@esri.com

gaolig commented 8 years ago

Thanks Mike. I sent an email with a file geodatabase containing the feature class with null geometry.

I edited the versioned (good) data in SDE by creating (6) features, and then tried running the script again. It added all rows to the feature service except for the ones that I had just created. The total count displayed was correct at 8,580; however only 8,574 rows were added to the feature service.

8574/8580 features added 8574 features added

I also reconciled and posted to default, and tried again, but get the same result.

If I export the above feature class to a file GDB, then the script adds all 8,580 rows.

Are there any known issues with using SDE or versioned data?

MikeMillerGIS commented 8 years ago

I did not get the email, can you verify it was sent. I am not aware of any issues with versioned data

MikeMillerGIS commented 8 years ago

Thanks for the data. I enhanced the function to report out the bad features and provide more details along the way. https://github.com/Esri/ArcREST/commit/fc201f38f179b232695b60afcc1619f61548e2d6

One thing that this exposed is how our chunking logic fails on non sequential OIDs. So I added logic that uses numpy to get a list of OIDs to build the sql statements to use equal chunks. https://github.com/Esri/ArcREST/commit/fbee46282c59e77babc077c30322861f7f3a3cff

MikeMillerGIS commented 8 years ago

Here is the example output: 8580 features in layer 2000 features in the chunk Error info: {u'success': False, u'globalId': u'7CF9BBB2-FA6F-4DD2-BDA3-65084F39FCC2', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} 1999 features added in this chunk 1999/8580 features added, 1 errors 2000 features in the chunk 2000 features added in this chunk 3999/8580 features added, 1 errors 2000 features in the chunk Error info: {u'success': False, u'globalId': u'BA627EC9-FF1B-42B5-BF25-1D103E2A2DCB', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'DA678DB5-7FDB-4AD4-A56A-C62D90344F22', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'34269B5F-353D-47C8-BEC8-E17D854F28C3', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} 1997 features added in this chunk 5996/8580 features added, 4 errors 2000 features in the chunk Error info: {u'success': False, u'globalId': u'92A1FF60-A3A1-4EA3-8A6B-EDD9532895E4', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'ECBBE25F-B682-40EC-BC7B-BD51145CACA4', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'DB97AC33-A3B1-48BD-B2F9-B6AFDF382FD3', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'939F22C6-198D-41AC-8D94-F25D37ED0EB8', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} 1996 features added in this chunk 7992/8580 features added, 8 errors 580 features in the chunk Error info: {u'success': False, u'globalId': u'05A6BFC5-60DB-47C3-BF56-C3586EBDD18B', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'951B39FB-1BA3-4B10-A929-C3582313F375', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'9622036A-E501-4840-AEBE-006613CE4BB8', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'4274CEE2-C356-40AD-BCDB-13AEF1D849E3', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} Error info: {u'success': False, u'globalId': u'2470B5D2-74D8-40A5-A504-79E4E1BE274F', u'objectId': None, u'error': {u'code': 1000, u'description': u'24126: Point coordinates cannot be infinite or not a number (NaN).'}} 575 features added in this chunk 8567/8580 features added, 13 errors 8580 features processed