<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: my python script to check for duplicates is sometimes removing data. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622767#M74350</link>
    <description>&lt;P&gt;I also have some scripts that remove the layer for what ever reason, annoying ESRI bug is my guess. the issue is the Water Later lines,&amp;nbsp;AddJoin requires the input to be a layer in the current map, not just a feature class name. So create feature layres, something like this,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;F = ("Sanitary Sewer Manholes", "Water Network Structures", "Water Fittings", 
     "Water System Valves", "Water Service Connections", "Water Hydrants", 
     "Sewer Gravity Mains", "Sewer Pressurized Mains", "Storm Drain Pipes", 
     "Water Lateral Lines", "Water Mains")

for a in F:  # No need for counter 'b', just iterate directly
    s = str(a).replace(" ", "_")
    o = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" + s + "_findidencal" + str(9)
    
    # First create a feature layer from the feature class
    layer_name = a + "_layer"
    arcpy.MakeFeatureLayer_management(a, layer_name)
    
    arcpy.management.FindIdentical(
        in_dataset=a,
        out_dataset=o,
        fields="FACILITYID",
        xy_tolerance=None,
        z_tolerance=0,
        output_record_option="ONLY_DUPLICATES")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This how I would write the code, untested but hopefully it helps.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;F = ("Sanitary Sewer Manholes", "Water Network Structures", "Water Fittings", 
     "Water System Valves", "Water Service Connections", "Water Hydrants", 
     "Sewer Gravity Mains", "Sewer Pressurized Mains", "Storm Drain Pipes", 
     "Water Lateral Lines", "Water Mains")

for a in F:  # No need for counter 'b', just iterate directly
    s = str(a).replace(" ", "_")
    o = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" + s + "_findidencal" + str(9)
    
    # First create a feature layer from the feature class
    layer_name = a + "_layer"
    arcpy.MakeFeatureLayer_management(a, layer_name)
    
    arcpy.management.FindIdentical(
        in_dataset=a,
        out_dataset=o,
        fields="FACILITYID",
        xy_tolerance=None,
        z_tolerance=0,
        output_record_option="ONLY_DUPLICATES")

    count_result = arcpy.management.GetCount(o)
    count = int(count_result[0])
    
    if count &amp;gt; 0:
        print("Duplicate entries in " + str(a))
        print(f"Number of duplicates found: {count}")
        
        # Use the layer instead of the feature class name
        arcpy.management.AddJoin(
            in_layer_or_view=layer_name,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )

        arcpy.management.SelectLayerByAttribute(
            in_layer_or_view=layer_name,
            selection_type="NEW_SELECTION",
            where_clause="IN_FID IS NOT NULL",
            invert_where_clause=None
        )
    else:
        print("no Duplicate in " + str(a))

# For the MBID check, you should similarly create a layer first
arcpy.MakeFeatureLayer_management("Water Service Connections", "Water_Service_Connections_layer")

m = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\MBID_duplicate" + str(1)

arcpy.management.SelectLayerByAttribute(
    in_layer_or_view="Water_Service_Connections_layer",
    selection_type="NEW_SELECTION",
    where_clause="MBID IS NOT NULL",
    invert_where_clause=None
)

arcpy.management.FindIdentical(
    in_dataset="Water_Service_Connections_layer",
    out_dataset=m,
    fields="MBID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES"
)

count_result = arcpy.management.GetCount(m)  # You need to get the count here
count = int(count_result[0])

if count &amp;gt; 0:
    print("Duplicate MBID in Meters")
    print(f"Number of duplicates found: {count}")
    arcpy.management.AddJoin(
        in_layer_or_view="Water_Service_Connections_layer",
        in_field="OBJECTID",
        join_table=m,
        join_field="IN_FID",
        join_type="KEEP_ALL",
        index_join_fields="NO_INDEX_JOIN_FIELDS",
        rebuild_index="NO_REBUILD_INDEX",
        join_operation="JOIN_ONE_TO_FIRST"
    )

    arcpy.management.SelectLayerByAttribute(
        in_layer_or_view="Water_Service_Connections_layer",
        selection_type="NEW_SELECTION",
        where_clause="IN_FID IS NOT NULL",
        invert_where_clause=None
    )
else:
    print("no Duplicate MBIDs")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jun 2025 17:50:10 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2025-06-11T17:50:10Z</dc:date>
    <item>
      <title>my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622616#M74340</link>
      <description>&lt;P&gt;My script is sometimes removing data from my map. I have developed a script to check a key field in several feature classes for duplicates. The script does work sometimes, but other times, it throws an error, error&amp;nbsp;000732. This mainly happens to 2 feature classes, one in which duplicates are found, and the other is the one that needs to test 2 different fields.&amp;nbsp; Before running the script, I verified the layer was in the TOC and on the map. However,&amp;nbsp;it was gone when I checked the TOC after the error.&amp;nbsp; &amp;nbsp;The strange thing is it can run the find identical in the loop fine without error, but it throws the error when it comes to the add join function. This also happens with the layer in which I need to check two fields. The find identical for the first field runs fine, but the find identical on the 2nd field can return the error. Any insights would be appreciated.&lt;/P&gt;&lt;P&gt;my code is:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;F=("Sanitary Sewer Manholes","Water Network Structures","Water Fittings","Water System Valves","Water Service Connections","Water Hydrants","Sewer Gravity Mains","Sewer Pressurized Mains","Storm Drain Pipes", "Water Lateral Lines", "Water Mains")
b =0 

for e in F:
    a=F[b]
    s=str(a).replace(" ", "_")
    o= "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" +s+"_findidencal"+str(9)
    m="C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\MBID_duplicate" + str(1)
   
    arcpy.management.FindIdentical(
    in_dataset= a,
    out_dataset=o,
    fields="FACILITYID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES")

    count_result = arcpy.management.GetCount(o)
    count = int(count_result[0])
    
    
    if count &amp;gt; 0:
        print("Duplicate entries in "+str (a) )
        print(f"Number of duplicates found: {count}")
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )


        arcpy.management.SelectLayerByAttribute(
            in_layer_or_view= a,
            selection_type="NEW_SELECTION",
            where_clause="IN_FID IS NOT NULL",
            invert_where_clause=None
            )
    

    else:
        print("no Duplicate in " + str(a) )

    
    b=b+1


arcpy.management.SelectLayerByAttribute(
    in_layer_or_view="Water Service Connections",
    selection_type="NEW_SELECTION",
    where_clause="MBID IS NOT NULL",
    invert_where_clause=None
)

arcpy.management.FindIdentical(
    in_dataset="Water Service Connections",
    out_dataset=m,
    fields="MBID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES"
)

if count &amp;gt; 0:
        print("Duplicate MBID in Meters " )
        print(f"Number of duplicates found: {count}")
        arcpy.management.AddJoin(
            in_layer_or_view="Water Service Connections",
            in_field="OBJECTID",
            join_table=m,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )


        arcpy.management.SelectLayerByAttribute(
            in_layer_or_view= "Water Service Connections",
            selection_type="NEW_SELECTION",
            where_clause="IN_FID IS NOT NULL",
            invert_where_clause=None
            )

else:
        print("no Duplicate MBIDs ")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pro 3.5.1&lt;/P&gt;&lt;P&gt;data source: enterprise geodata base&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 13:50:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622616#M74340</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-06-11T13:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622646#M74341</link>
      <description>&lt;P&gt;I think one of your issues is with the AddJoin and SelectLayerByAttribute, it can create the appears of deleted features.&amp;nbsp;&lt;/P&gt;&lt;P&gt;join_type="KEEP_ALL" keeps all records from the left table (a) and includes only matching rows from the join table (o) where OBJECTID = IN_FID.&lt;/P&gt;&lt;P&gt;Filtering with "IN_FID IS NOT NULL" isolates features identified as duplicates.&lt;/P&gt;&lt;P&gt;Unmatched features aren’t deleted they're just unselected or excluded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Always work with feature layers not feature classes, and clear the selection after your done.&amp;nbsp;&lt;/P&gt;&lt;P&gt;clear join after SelectLayerByAttribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 14:55:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622646#M74341</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-06-11T14:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622663#M74342</link>
      <description>&lt;P&gt;I'm noticing that you have a primary loop that loops over features followed by the same thing flattened. Is that intentional?&lt;/P&gt;&lt;P&gt;You're also not changing the name of the out `MBID_duplicate` layer. it's always evaluating to "...MBID_duplicate1". It can also help to use verbose variable names. Here's a modified version of your code that tries to simplify the main loop so you can identify your error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from pathlib import Path
from functools import partial

features=(
    "Sanitary Sewer Manholes",
    "Water Network Structures",
    "Water Fittings",
    "Water System Valves",
    "Water Service Connections",
    "Water Hydrants",
    "Sewer Gravity Mains",
    "Sewer Pressurized Mains",
    "Storm Drain Pipes",
    "Water Lateral Lines",
    "Water Mains",
)

gdb = Path(r"C:\Users\lconner\Documents\ArcGIS\Projects\edit_map6\edit_map6.gdb")


p_find = partial(
    arcpy.management.FindIdentical(
    fields="FACILITYID",
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES",
    )
)

p_join = partial(
    arcpy.management.AddJoin(
            in_field="OBJECTID",
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST",
    )
)

p_select = partial(
    arcpy.management.SelectLayerByAttribute(
        selection_type="NEW_SELECTION",
        where_clause="IN_FID IS NOT NULL",
    )
)

for feature in features:    
    feature=feature.replace(" ", "_")
    
    # This was originally writing all mbid_duplicate tables to the
    # same features `MBID_duplicate1`
    out_feature = gdb / f"FindIdentical_{feature}"
    mbid_feature = gdb / f"MBID_duplicate_{feature}"
    
    # Originally you were counting the input features, not the identical table
    identicals, _ = p_find(in_dataset=feature, out_dataset=out_feature)
    count = sum(1 for _ in arcpy.da.SearchCursor(identicals, ['OID@']))
    
    # Continue the loop if no identicals found
    if count == 0:
        print(f"No duplicate in {feature}" )
        continue
    
    # Log identical counts and add join, then select the features that don't have a null IN_FID
    print(f"{count} duplicate entries in {feature}")
    p_join(in_layer_or_view=feature, join_table=out_feature)
    p_select(in_layer_or_view=feature)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can ignore or remove the `partial` blocks, I just did that to pre-fill the constant arguments in the tool calls and bubble them up to the top of the script in case you want to change them later.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 15:24:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622663#M74342</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T15:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622741#M74347</link>
      <description>&lt;P data-unlink="true"&gt;@&amp;nbsp;TonyAlmeida, The problem is not that features are disappearing from the feature layer; the problem is that the feature layer is being removed from my map in the middle of running the script. I know that when I open the attribute table, I just see the selected duplicates. Would&amp;nbsp; the add join or&amp;nbsp; SelectLayerByAttribute cause the feature layer to be removed from the map?&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;, Yes, the loop and then rechecking the one file are intentional. All feature layers need the FID checked for duplicates. However, only the meters have the MBID field, and thus, they are the only feature layer where that needs to be checked, too.&lt;/P&gt;&lt;P data-unlink="true"&gt;As of now, the names of the outputs are not causing a problem. I thought that might be the issue.&amp;nbsp; I added the&amp;nbsp;+ str(1) on the end as a crude way to get a unique output name, as I could change the number in the (). It would be best to generate a unique output name every time. It would be appreciated if you could point me to some article or explanation on how to do that, but I don't think that is causing the problem.&lt;/P&gt;&lt;P data-unlink="true"&gt;This is the first I have heard of&amp;nbsp;partial functions, so I will need to read up on them before I use them. Do you have any good resources for that? Would the absence of the partial function cause it to remove a feature layer from the map in the middle of a script? Right now, I am focused on finding what is causing the problem. I am not sure how simplifying the loop will help with that.&lt;/P&gt;&lt;P data-unlink="true"&gt;Here is the printout and error message I am getting:&lt;/P&gt;&lt;P data-unlink="true"&gt;the script returns:&lt;/P&gt;&lt;PRE&gt;no Duplicate in Sanitary Sewer Manholes
no Duplicate in Water Network Structures
no Duplicate in Water Fittings
no Duplicate in Water System Valves
no Duplicate in Water Service Connections
no Duplicate in Water Hydrants
no Duplicate in Sewer Gravity Mains
no Duplicate in Sewer Pressurized Mains
no Duplicate in Storm Drain Pipes
Duplicate entries in Water Lateral Lines
Number of duplicates found: 6&lt;/PRE&gt;&lt;P data-unlink="true"&gt;The error in full i am getting is:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;ExecuteError&lt;/SPAN&gt;                              Traceback (most recent call last)
Cell &lt;SPAN class=""&gt;In[5], line 25&lt;/SPAN&gt;
&lt;SPAN class=""&gt;     23&lt;/SPAN&gt;     &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Duplicate entries in &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;+&lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt; (a) )
&lt;SPAN class=""&gt;     24&lt;/SPAN&gt;     &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Number of duplicates found: &lt;/SPAN&gt;&lt;SPAN class=""&gt;{&lt;/SPAN&gt;count&lt;SPAN class=""&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;)
&lt;SPAN class=""&gt;---&amp;gt; 25&lt;/SPAN&gt;     arcpy&lt;SPAN&gt;.&lt;/SPAN&gt;management&lt;SPAN&gt;.&lt;/SPAN&gt;AddJoin(
&lt;SPAN class=""&gt;     26&lt;/SPAN&gt;         in_layer_or_view&lt;SPAN&gt;=&lt;/SPAN&gt;a,
&lt;SPAN class=""&gt;     27&lt;/SPAN&gt;         in_field&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;OBJECTID&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     28&lt;/SPAN&gt;         join_table&lt;SPAN&gt;=&lt;/SPAN&gt;o,
&lt;SPAN class=""&gt;     29&lt;/SPAN&gt;         join_field&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;IN_FID&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     30&lt;/SPAN&gt;         join_type&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;KEEP_ALL&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     31&lt;/SPAN&gt;         index_join_fields&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;NO_INDEX_JOIN_FIELDS&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     32&lt;/SPAN&gt;         rebuild_index&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;NO_REBUILD_INDEX&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     33&lt;/SPAN&gt;         join_operation&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;JOIN_ONE_TO_FIRST&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;
&lt;SPAN class=""&gt;     34&lt;/SPAN&gt;     )
&lt;SPAN class=""&gt;     37&lt;/SPAN&gt;     arcpy&lt;SPAN&gt;.&lt;/SPAN&gt;management&lt;SPAN&gt;.&lt;/SPAN&gt;SelectLayerByAttribute(
&lt;SPAN class=""&gt;     38&lt;/SPAN&gt;         in_layer_or_view&lt;SPAN&gt;=&lt;/SPAN&gt; a,
&lt;SPAN class=""&gt;     39&lt;/SPAN&gt;         selection_type&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;NEW_SELECTION&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     40&lt;/SPAN&gt;         where_clause&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;IN_FID IS NOT NULL&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;     41&lt;/SPAN&gt;         invert_where_clause&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;None&lt;/SPAN&gt;
&lt;SPAN class=""&gt;     42&lt;/SPAN&gt;         )
&lt;SPAN class=""&gt;     45&lt;/SPAN&gt; &lt;SPAN class=""&gt;else&lt;/SPAN&gt;:

File &lt;SPAN class=""&gt;C:\Program&lt;/SPAN&gt;&lt;SPAN class=""&gt; Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py:13600&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;AddJoin&lt;/SPAN&gt;&lt;SPAN class=""&gt;(in_layer_or_view, in_field, join_table, join_field, join_type, index_join_fields, rebuild_index, join_operation)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;  13598&lt;/SPAN&gt;     &lt;SPAN class=""&gt;return&lt;/SPAN&gt; retval
&lt;SPAN class=""&gt;  13599&lt;/SPAN&gt; &lt;SPAN class=""&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;Exception&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; e:
&lt;SPAN class=""&gt;&amp;gt; 13600&lt;/SPAN&gt;     &lt;SPAN class=""&gt;raise&lt;/SPAN&gt; e

File &lt;A target="_blank"&gt;&lt;SPAN class=""&gt;C:\Program&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN class=""&gt; Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py:13582&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;AddJoin&lt;/SPAN&gt;&lt;SPAN class=""&gt;(in_layer_or_view, in_field, join_table, join_field, join_type, index_join_fields, rebuild_index, join_operation)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;  13578&lt;/SPAN&gt; &lt;SPAN class=""&gt;from&lt;/SPAN&gt; &lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcobjects&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcobjectconversion&lt;/SPAN&gt; &lt;SPAN class=""&gt;import&lt;/SPAN&gt; convertArcObjectToPythonObject
&lt;SPAN class=""&gt;  13580&lt;/SPAN&gt; &lt;SPAN class=""&gt;try&lt;/SPAN&gt;:
&lt;SPAN class=""&gt;  13581&lt;/SPAN&gt;     retval &lt;SPAN&gt;=&lt;/SPAN&gt; convertArcObjectToPythonObject(
&lt;SPAN class=""&gt;&amp;gt; 13582&lt;/SPAN&gt;         gp&lt;SPAN&gt;.&lt;/SPAN&gt;AddJoin_management(
&lt;SPAN class=""&gt;  13583&lt;/SPAN&gt;             &lt;SPAN&gt;*&lt;/SPAN&gt;gp_fixargs(
&lt;SPAN class=""&gt;  13584&lt;/SPAN&gt;                 (
&lt;SPAN class=""&gt;  13585&lt;/SPAN&gt;                     in_layer_or_view,
&lt;SPAN class=""&gt;  13586&lt;/SPAN&gt;                     in_field,
&lt;SPAN class=""&gt;  13587&lt;/SPAN&gt;                     join_table,
&lt;SPAN class=""&gt;  13588&lt;/SPAN&gt;                     join_field,
&lt;SPAN class=""&gt;  13589&lt;/SPAN&gt;                     join_type,
&lt;SPAN class=""&gt;  13590&lt;/SPAN&gt;                     index_join_fields,
&lt;SPAN class=""&gt;  13591&lt;/SPAN&gt;                     rebuild_index,
&lt;SPAN class=""&gt;  13592&lt;/SPAN&gt;                     join_operation,
&lt;SPAN class=""&gt;  13593&lt;/SPAN&gt;                 ),
&lt;SPAN class=""&gt;  13594&lt;/SPAN&gt;                 &lt;SPAN class=""&gt;True&lt;/SPAN&gt;,
&lt;SPAN class=""&gt;  13595&lt;/SPAN&gt;             )
&lt;SPAN class=""&gt;  13596&lt;/SPAN&gt;         )
&lt;SPAN class=""&gt;  13597&lt;/SPAN&gt;     )
&lt;SPAN class=""&gt;  13598&lt;/SPAN&gt;     &lt;SPAN class=""&gt;return&lt;/SPAN&gt; retval
&lt;SPAN class=""&gt;  13599&lt;/SPAN&gt; &lt;SPAN class=""&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;Exception&lt;/SPAN&gt; &lt;SPAN class=""&gt;as&lt;/SPAN&gt; e:

File &lt;SPAN class=""&gt;C:\Program&lt;/SPAN&gt;&lt;SPAN class=""&gt; Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py:533&lt;/SPAN&gt;, in &lt;SPAN class=""&gt;Geoprocessor.__getattr__.&amp;lt;locals&amp;gt;.&amp;lt;lambda&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;(*args)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;    531&lt;/SPAN&gt; val &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;getattr&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;_gp, attr)
&lt;SPAN class=""&gt;    532&lt;/SPAN&gt; &lt;SPAN class=""&gt;if&lt;/SPAN&gt; &lt;SPAN&gt;callable&lt;/SPAN&gt;(val):
&lt;SPAN class=""&gt;--&amp;gt; 533&lt;/SPAN&gt;     &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;lambda&lt;/SPAN&gt; &lt;SPAN&gt;*&lt;/SPAN&gt;args: val(&lt;SPAN&gt;*&lt;/SPAN&gt;gp_fixargs(args, &lt;SPAN class=""&gt;True&lt;/SPAN&gt;))
&lt;SPAN class=""&gt;    534&lt;/SPAN&gt; &lt;SPAN class=""&gt;else&lt;/SPAN&gt;:
&lt;SPAN class=""&gt;    535&lt;/SPAN&gt;     &lt;SPAN class=""&gt;return&lt;/SPAN&gt; convertArcObjectToPythonObject(val)

&lt;SPAN class=""&gt;ExecuteError&lt;/SPAN&gt;: Failed to execute. Parameters are not valid.
ERROR 000732: Layer Name or Table View: Dataset Water Lateral Lines does not exist or is not supported
Failed to execute (AddJoin).&lt;/PRE&gt;&lt;P&gt;P.S. is there any thing i could have added to my original post to help clarify it?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:16:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622741#M74347</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-06-11T17:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622764#M74349</link>
      <description>&lt;P&gt;Simplifying the loop just makes it easier to see exactly where the code is failing. I believe your issue is still in the fact that you are looping over the features and essentially doing nothing. Each loop overwrites the output of the previous. I fixed that and commented it in my version. When you go to join, you're joining the last table in the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are also not using the updated name (something I also fixed in my version) and are calling the space delimited version of the feature name which seems to not exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only did the partials and the loop simplification to make it clear that your core logic was incorrect. Sometimes cleaning things up like that can make the issue super obvious.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:48:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622764#M74349</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T17:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622767#M74350</link>
      <description>&lt;P&gt;I also have some scripts that remove the layer for what ever reason, annoying ESRI bug is my guess. the issue is the Water Later lines,&amp;nbsp;AddJoin requires the input to be a layer in the current map, not just a feature class name. So create feature layres, something like this,&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;F = ("Sanitary Sewer Manholes", "Water Network Structures", "Water Fittings", 
     "Water System Valves", "Water Service Connections", "Water Hydrants", 
     "Sewer Gravity Mains", "Sewer Pressurized Mains", "Storm Drain Pipes", 
     "Water Lateral Lines", "Water Mains")

for a in F:  # No need for counter 'b', just iterate directly
    s = str(a).replace(" ", "_")
    o = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" + s + "_findidencal" + str(9)
    
    # First create a feature layer from the feature class
    layer_name = a + "_layer"
    arcpy.MakeFeatureLayer_management(a, layer_name)
    
    arcpy.management.FindIdentical(
        in_dataset=a,
        out_dataset=o,
        fields="FACILITYID",
        xy_tolerance=None,
        z_tolerance=0,
        output_record_option="ONLY_DUPLICATES")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This how I would write the code, untested but hopefully it helps.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;F = ("Sanitary Sewer Manholes", "Water Network Structures", "Water Fittings", 
     "Water System Valves", "Water Service Connections", "Water Hydrants", 
     "Sewer Gravity Mains", "Sewer Pressurized Mains", "Storm Drain Pipes", 
     "Water Lateral Lines", "Water Mains")

for a in F:  # No need for counter 'b', just iterate directly
    s = str(a).replace(" ", "_")
    o = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" + s + "_findidencal" + str(9)
    
    # First create a feature layer from the feature class
    layer_name = a + "_layer"
    arcpy.MakeFeatureLayer_management(a, layer_name)
    
    arcpy.management.FindIdentical(
        in_dataset=a,
        out_dataset=o,
        fields="FACILITYID",
        xy_tolerance=None,
        z_tolerance=0,
        output_record_option="ONLY_DUPLICATES")

    count_result = arcpy.management.GetCount(o)
    count = int(count_result[0])
    
    if count &amp;gt; 0:
        print("Duplicate entries in " + str(a))
        print(f"Number of duplicates found: {count}")
        
        # Use the layer instead of the feature class name
        arcpy.management.AddJoin(
            in_layer_or_view=layer_name,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )

        arcpy.management.SelectLayerByAttribute(
            in_layer_or_view=layer_name,
            selection_type="NEW_SELECTION",
            where_clause="IN_FID IS NOT NULL",
            invert_where_clause=None
        )
    else:
        print("no Duplicate in " + str(a))

# For the MBID check, you should similarly create a layer first
arcpy.MakeFeatureLayer_management("Water Service Connections", "Water_Service_Connections_layer")

m = "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\MBID_duplicate" + str(1)

arcpy.management.SelectLayerByAttribute(
    in_layer_or_view="Water_Service_Connections_layer",
    selection_type="NEW_SELECTION",
    where_clause="MBID IS NOT NULL",
    invert_where_clause=None
)

arcpy.management.FindIdentical(
    in_dataset="Water_Service_Connections_layer",
    out_dataset=m,
    fields="MBID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES"
)

count_result = arcpy.management.GetCount(m)  # You need to get the count here
count = int(count_result[0])

if count &amp;gt; 0:
    print("Duplicate MBID in Meters")
    print(f"Number of duplicates found: {count}")
    arcpy.management.AddJoin(
        in_layer_or_view="Water_Service_Connections_layer",
        in_field="OBJECTID",
        join_table=m,
        join_field="IN_FID",
        join_type="KEEP_ALL",
        index_join_fields="NO_INDEX_JOIN_FIELDS",
        rebuild_index="NO_REBUILD_INDEX",
        join_operation="JOIN_ONE_TO_FIRST"
    )

    arcpy.management.SelectLayerByAttribute(
        in_layer_or_view="Water_Service_Connections_layer",
        selection_type="NEW_SELECTION",
        where_clause="IN_FID IS NOT NULL",
        invert_where_clause=None
    )
else:
    print("no Duplicate MBIDs")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 17:50:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622767#M74350</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-06-11T17:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622808#M74356</link>
      <description>&lt;P&gt;I am taking that there is no way to mitigate the problem of the script removing the layer. Is there some where I can give the details to Esri so they can work on a fix for the problem.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 18:56:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622808#M74356</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-06-11T18:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622816#M74357</link>
      <description>&lt;P&gt;No, you're just using a constant string value for the output layer and so its being overwritten. If you want the layer to persist, you need the name to change for each feature. I Did that in the first few lines of my simplified loop by adding the feature name to the end of the layer name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to clarify, `str(1)` is not unique. It's the equvalent of just putting a "1" in there. You need that value to change.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jun 2025 19:15:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622816#M74357</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T19:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622861#M74361</link>
      <description>&lt;P&gt;Okay, I think I was initially confused by your question. I now see that you're trying to check for duplicate IDs in all feature classes. I'm gonna revise my initial response with one that actually tries to solve your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did manage to get it all done using SearchCursors and Python's built in mapping. All you need to do is create a dictionary of FACILITYID keys with a sequence of something that contains the name of the feature class and the OBJECTID for the duplicate feature (for selection later).&lt;/P&gt;&lt;P&gt;After filtering out the facility records that only have one hit, you can then re-map those duplicates to a new mapping of Feature Class to Object IDs (since the original check was against all Feature Classes). From there we can print out the feature classes that have no duplicates as well as the count of duplicates in each feature class that does contain collisions:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pathlib import Path
from arcpy.da import SearchCursor
from arcpy.mp import Layer
from arcpy.management import (
    SelectLayerByAttribute,
    CopyFeatures,
)

feature_classes=(
    "Sanitary Sewer Manholes",
    "Water Network Structures",
    "Water Fittings",
    "Water System Valves",
    "Water Service Connections",
    "Water Hydrants",
    "Sewer Gravity Mains",
    "Sewer Pressurized Mains",
    "Storm Drain Pipes",
    "Water Lateral Lines",
    "Water Mains",
)

gdb = Path(r"C:\Users\lconner\Documents\ArcGIS\Projects\edit_map6\edit_map6.gdb")

# Initialize a dictionary that will contain duplicate entries
# in the form: {&amp;lt;facility&amp;gt;: [(&amp;lt;feature_class&amp;gt;, &amp;lt;oid&amp;gt;), ...]}
facility_mapping: dict[int|str, list[tuple[str, int]]] = {}

# Build the mapping of facilities
for feature_class in feature_classes:
    # Sanitize name
    feature_class = feature_class.replace(' ', '_')
    
    # The `feature_class` in this call might need to be interpolated to see your features, 
    # Possibly with the gdb global above if that's where they live
    for facility_id, object_id in SearchCursor(feature_class, ['FACILITYID', 'OID@']):
        facility_mapping.setdefault(facility_id, [])
        facility_mapping[facility_id].append((feature_class, object_id))

# Filter the mapping to only have facilities with duplicates
facility_mapping = {
    facility: duplicates
    for facility, duplicates in facility_mapping.items()
    if len(duplicates) &amp;gt; 1
}

# Clear current selection
SelectLayerByAttribute(selection_type='CLEAR_SELECTION')

# Build a selection map for selecting duplicates in all FCs
selections: dict[str, list[int]] = {}
for _, record in facility_mapping.items():
    # Unpack the record
    fc, oid = record
    
    # Add the OID to the selection mapping
    selections.setdefault(fc, [])
    selections[fc].append(oid)

# Final loop for printing and selecting
for fc in feature_classes:
    # Make sure this points to your features!
    fc = fc.replace(' ', '_')
    if fc not in selections:
        print(f"No duplicates found in {fc.replace('_', ' ')}")
        continue
    
    print(f"Found {len(selections[fc])} duplicates in {fc.replace('_', ' ')}")
    SelectLayerByAttribute(
        in_layer_or_view=fc, 
        selection_type='ADD_TO_SELECTION', 
        where_clause=f"OBJECTID IN ({','.join(selections[fc])})",
    )
    
    # Uncomment to create a new layer with duplicates
    # CopyFeatures(fc, f"{fc}_duplicates")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 11 Jun 2025 20:44:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1622861#M74361</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-11T20:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1623117#M74366</link>
      <description>&lt;P&gt;ok, I have a few questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. would this approach keep arc pro from &lt;STRONG&gt;sometimes&lt;/STRONG&gt; removing&amp;nbsp; Water Lateral Lines from the project while in the middle of executing the script.&lt;/P&gt;&lt;P&gt;2 Is there a way or approach that generally stops&amp;nbsp; arc pro form arbitrarily removing data from the project in the middle of running the script?&lt;/P&gt;&lt;P&gt;3. Is there a reason you are not using the built in find identical tool instead of using long hand to specify the operation?&lt;/P&gt;&lt;P&gt;I am trying tying to see if i can get your script to work for me. this is my 1st time with the Search Cursor function so it might take some time to figure it out.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jun 2025 16:50:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1623117#M74366</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-06-12T16:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: my python script to check for duplicates is sometimes removing data.</title>
      <link>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1623486#M74371</link>
      <description>&lt;P&gt;Your setup isn't removing data, it's overwriting layers. The layer data source is still there, but since you're creating a new layer with the same name, it appears to vanish.&lt;/P&gt;&lt;P&gt;What I did here is just ignore the layers entirely. I'm working directly on the source data. First I load all the features into memory, build a mapping (dict) that organizes the features from all input sources into a single location. Then I find all records that have collisions between the datasets (len (mapping[fid]) &amp;gt; 1).&lt;/P&gt;&lt;P&gt;I only chose to avoid the function call to FindIdentical, because I already know what I need and a hash map can accommodate that perfectly. If you needed the side effects of running that function, you should absolutely use it, but since all we need is a sequence of feature names and object IDs, we can drop that complexity.&lt;/P&gt;&lt;P&gt;If you did want to continue using the layer operations and higher level functions, you can. I'd just make sure that you are putting them in a memory layer instead of writing them directly to a featureclass on disk.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

fc = 'my_fc'

join = arcpy.management.AddJoin(f'memory/{fc}', ...).getOutput(0)

# Other operations on join
...

final = arcpy.management.DeleteIdentical(join, ...).getOutput(0)

# Here we finally output a layer
arcpy.management.CopyFeatures(final, f'&amp;lt;Full_Path&amp;gt;/{fc}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In that snippet, the join is an intermediate step and we don't output it to the map. We only do that at the end when CopyFeatures is called. Creating intermediate layers while the environment is set to addOutputsToMap can be a pain. You can also use EnvManager to prevent layers from being overwritten and added:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import EnvManager

fc = 'my_fc'

with EnvManager(addOutputsToMap=False, overwriteOutput=False):
    join = arcpy.management.AddJoin(f'{fc}', ...).getOutput(0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the end there's a ton of different ways to do things with arcpy. I tend to stick to the most pure python I can since the APIs for some of the tool functions can be difficult to work with or oddly documented. A Cursor is just a quick way to turn your source data into Python objects which means now you just have a data science problem on your hands instead of a workflow problem.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jun 2025 16:22:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/my-python-script-to-check-for-duplicates-is/m-p/1623486#M74371</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-13T16:22:11Z</dc:date>
    </item>
  </channel>
</rss>

