<?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: delete_features() fails sometimes with error 400 in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-features-fails-sometimes-with-error-400/m-p/1234246#M8044</link>
    <description>&lt;P&gt;Resolved: sorry I took a closer look at this and the issue is NOT with the delete_features() method, it's actually just above this where I am first checking to see if there are any features to delete by executing a simple layer.query().&amp;nbsp; I think it's simply a matter of too many features being returned in that request and attempting to count the results of the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead, I just simply added the return_count_only=True parameter to accomplish this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;recQuery = layer.query(where="{} &amp;lt; '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),return_count_only=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which validates just fine and allows me to check the recCount and apply my conditional logic as needed.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2022 19:45:04 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2022-11-22T19:45:04Z</dc:date>
    <item>
      <title>delete_features() fails sometimes with error 400</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-features-fails-sometimes-with-error-400/m-p/1234236#M8043</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a Notebook hosted in our AGOL org that will sometimes fail with error code 400 "Cannot perform query. Invalid query parameters. Unable to perform query. Please check your parameters.".&amp;nbsp; But successfully executes at other times.&amp;nbsp; The 'where' parameter is built at runtime to setup a datetime query and full statement looks like,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layer.delete_features(where="{} &amp;lt; '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),future=True)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The actual query at runtime would read as (or the datetime from 479 days ago compared to utcnow(),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;location_timestamp &amp;lt; '2021-07-31 18:55:18'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When running this same exact where against the REST query api it works as expected.&amp;nbsp; Again, this will&amp;nbsp; &amp;nbsp;successfully run the delete_features() method at times so I'm unsure how to trace the issue if it is an intermittent problem as this Notebook runs on AGOL hosted environment.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:23:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-features-fails-sometimes-with-error-400/m-p/1234236#M8043</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-11-22T19:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: delete_features() fails sometimes with error 400</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-features-fails-sometimes-with-error-400/m-p/1234246#M8044</link>
      <description>&lt;P&gt;Resolved: sorry I took a closer look at this and the issue is NOT with the delete_features() method, it's actually just above this where I am first checking to see if there are any features to delete by executing a simple layer.query().&amp;nbsp; I think it's simply a matter of too many features being returned in that request and attempting to count the results of the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead, I just simply added the return_count_only=True parameter to accomplish this,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;recQuery = layer.query(where="{} &amp;lt; '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),return_count_only=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which validates just fine and allows me to check the recCount and apply my conditional logic as needed.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 19:45:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/delete-features-fails-sometimes-with-error-400/m-p/1234246#M8044</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2022-11-22T19:45:04Z</dc:date>
    </item>
  </channel>
</rss>

