Unexpected behavior around unique constraint on field

982
3
Jump to solution
04-20-2018 01:01 PM
Trippetoe
Occasional Contributor III

I have taken advantage of the newly added capability of setting a unique constraint on a field in a hosted feature layer. I am seeing some odd behavior around that functionality.  Here's how to reproduce the behavior

  1. Create a new hosted feature layer in AGOL
  2. Add a text field, lets call it 'testid'
  3. Set a unique constraint on testid
  4. Add the hosted feature layer to a new map
  5. Use the Map Viewer Edit tool to create a new feature and do not enter a value for 'testid'. Save that feature
  6. Now try to create another new feature

The system wont let me create a new feature. Instead, after clicking the place on the map where i want to add the new feature, no new feature is added and a popup window is displayed with the values from another feature in the hosted feature layer.  If i go back to feature with the missing value for testid and populate the field with a unique value, all goes back to working as expected.

I suspect it's happening because behind the scenes a new feature is created with 'null' or empty (or default if set) values for each attribute. And when the system sees a duplicated value, i.e. null/empty value for the field testid, the system can't handle that?

Anyone else see this behavior? Is this the expected behavior? 

0 Kudos
1 Solution

Accepted Solutions
StephanieWendel
Esri Contributor

Hey Tom Rippetoe

I saw Kelly Gerrow's message here. We have logged a bug for this:

BUG-000113512 Unable to create new features in a Hosted Feature Service that has a field with the unique constraint if a feature was added without a value in the constrained field.

It should appear on our support.esri.com in a couple days and/or if you submit a Case to Support Services we can attach you to it for additional tracking.

Thanks!

Stephanie

View solution in original post

3 Replies
KellyGerrow
Esri Frequent Contributor

Hey Tom,

This looks like a bug and better error messaging is needed. If you were to run into the issue in the future, would you prefer to have a unique field created and entered for such a field or receive an error message indicating that the field entered is not unique?

I'd suggest contacting support services so a trackable bug can be logged.

Thanks,

Kelly

0 Kudos
Trippetoe
Occasional Contributor III

Hi Kelly and Stephanie.

Thanks for tracking this issue and creating the bug report.

KGerrow-esristaff, I think there are two separate use cases here: 1) editing existing data and 2) creating new data. 

In the first case, i think an big, bright error message indicating that the value entered fails the 'uniqueness constraint' would be most helpful.  Currently, AGOL simply deletes the duplicated value, leaving the input empty.  That has caused us some problems when we didn't notice that the value we entered was replaced by a blank value (that's what got us stuck in the second use case).

The second case is a bit harder to work thru given AGOLs current pattern of creating a new record in the database as soon as the geometry is created. I don't know how it would/could work that AGOL hold the feature in memory, checking that all attributes pass their various constraints, and then having the user click a 'save' or 'insert' or some such button to send the data to the database.

Hopefully this helps. I love a good architecture discussion - it'd be interesting to know how you guys think about situations like this.

Tom

StephanieWendel
Esri Contributor

Hey Tom Rippetoe

I saw Kelly Gerrow's message here. We have logged a bug for this:

BUG-000113512 Unable to create new features in a Hosted Feature Service that has a field with the unique constraint if a feature was added without a value in the constrained field.

It should appear on our support.esri.com in a couple days and/or if you submit a Case to Support Services we can attach you to it for additional tracking.

Thanks!

Stephanie