Select to view content in your preferred language

delete_features() fails sometimes with error 400

492
1
Jump to solution
11-22-2022 11:23 AM
JamesCrandall
MVP Frequent Contributor

Hi all,

 

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.".  But successfully executes at other times.  The 'where' parameter is built at runtime to setup a datetime query and full statement looks like,

 

layer.delete_features(where="{} < '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),future=True)

 

The actual query at runtime would read as (or the datetime from 479 days ago compared to utcnow(),

 

location_timestamp < '2021-07-31 18:55:18'

 

 

When running this same exact where against the REST query api it works as expected.  Again, this will   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.

0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

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().  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.

 

Instead, I just simply added the return_count_only=True parameter to accomplish this,

 

recQuery = layer.query(where="{} < '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),return_count_only=True)

 

Which validates just fine and allows me to check the recCount and apply my conditional logic as needed.

View solution in original post

0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor

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().  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.

 

Instead, I just simply added the return_count_only=True parameter to accomplish this,

 

recQuery = layer.query(where="{} < '{}'".format(row.attributes['dateColumnName'],(datetime.utcnow() - timedelta(days=row.attributes['daysToKeep'])).strftime("%Y-%m-%d %H:%M:%S")),return_count_only=True)

 

Which validates just fine and allows me to check the recCount and apply my conditional logic as needed.

0 Kudos