Append() takes no keyword arguments

4709
4
02-12-2021 08:56 AM
pmccord
New Contributor III

I'm pretty new to the ArcGIS API for Python. I'm trying to use the Append function to append data from a source file geodatabase that is hosted on AGO to a target feature layer. I'm using the upsert parameter because, not only am I adding additional features to the target from the source, but I've also changed some of the attributes within the source and I want those changes reflected in the target.

What I'm trying to do is pretty basic I think, but when I run my script I get the message "append() takes no keyword arguments". 

Here's my code:

import os

from arcgis.gis import GIS


# Create a GIS connection to AGO where the test data is located
gis = GIS(url, username, password)

# Target feature layer (feature layer with fewer points that needs to be updated)
target_item = gis.content.get("1fbf6a4e1ebe4720aa7036a3d52f7544")
print("feature layer to update:", target_item)
target_lyr = target_item.layers

# Look for the unique field within the target layer
# simply verifies that I had a field with unique values in my target layer
"""
uk_flds = (f.fields for f in target_lyr[0].properties.indexes if f.isUnique)
for fld in target_lyr[0].properties.fields:
    if fld.name in uk_flds:
        print(f"{fld.name:30}{fld.type:25}isUnique")
    else:
        print(f"{fld.name:30}{fld.type:25}")
"""

# Source fgdb
src_lyr = gis.content.search("Water_system_valves_source")[0]
print(src_lyr)

# Run the Append function
target_lyr.append(
    source_table_name="test",
    item_id=src_lyr.id,
    upload_format="filegdb",
    upsert=True,
    skip_updates=False,
    use_globalids=False,
    update_geometry=True,
    append_fields=["FID", "VALVETYPE", "Creator"],
    rollback=False,
    skip_inserts=False,
    upsert_matching_field="FID",
)

 

The field with unique values that matches records between the two layers is "FID." I specified "FID", "VALVETYPE", and "Creator" in the append_fields parameter because VALVETYPE and Creator are the two fields where attribute values were changed in the source dataset. FID was specified because it is the unique identifier (I'm not sure if this is correct, but it's what I took away from some of the documentation). All of the fields are the same between the source and target layers, but they're in a slightly different order.

I primarily followed this resource: https://developers.arcgis.com/python/guide/appending-features/ (starting at the "Insert New Features and Update Existing Features - Upsert" section).

Any assistance would be appreciated. Thank you.

Tags (2)
4 Replies
DavidPike
MVP Frequent Contributor

I've not utilised this before, but if you're appending to a specific layer, wouldn't you need to reference an individual layer e.g.

target_lyr = target_item.layers[0]

 

pmccord
New Contributor III

Thank you David, you were right that I needed to alter the code to read:

target_lyr = target_item.layers[0]

I'm now getting an error of "Object reference not set to an instance of an object". My understanding is that this might be a field mappings issue between the source and target layers. I'm going to look into this a bit more and post any solution I find.

I believe that my fields are identical between the two layers, but I need to inspect it further.

JoeWaters1
New Contributor II

@pmccord did you get this working? I am running into the same error and am wondering if you found a solution.

pmccord
New Contributor III

@JoeWaters1 , I ultimately decided to run the Append tool from ArcGIS Pro on my AGO layers. The work I was doing didn't require using the Python API, so using the Append tool from Pro worked as an alternative for me.