Extra property in BackendlessUser

Hello.

In our project we use custom API created in “Business Logic”. For one of those API response we return
“BackendlessUser” objects with custom property inserted in that response. After client app calls the API all new “BackendlessUser” objects fetched via IDataStore contains that custom property. After that I cannot save “BackendlessUser” object because of that property, I get error “Unable to update user. Dynamic properties are disabled for this version of the application”

Hi Andrey,
Does the option “Enable Dynamic User Definition” is turned on?
If so, could you please create some code example describing the problem which would help us reproduce the problem?
Artur

No, “Enable Dynamic User Definition” is disabled. I understand why I get the error, because I save an object with one extra property. But I don’t understand why “BackendlessUser” object contains this extra property. Here is scenario:

  1. Request “BackendlessUser” objects via IDataStore
  2. IDataStore return an objects with N properties
  3. Call custom api via “CustomService”
  4. Custom api returns an objects with N+1 properties (this is OK)
  5. Request again “BackendlessUser” objects via IDataStore
  6. IDataStore return an objects with N + 1 properties (this is error, I don’t need extra property)

I can create example project if it helps.

Andrey, please, enable “Enable Dynamic User Definition” option of your app and try again.

Yes, If “Enable Dynamic User Definition” is on there is no error after saving “BackendlessUser” object. But the problem isn’t connected to saving, I don’t need the extra property in every new “BackendlessUser” object after using a custom api. I added example project.

In “viewDidLoad” app logins an user and then if user taps the button, app sends 3 requests

 @IBAction func onSendRequestsButtonTap(sender: AnyObject) {
        requestUsersViaDataStoreWithCompletion { 
            self.requestUsersViaCustomApiWithCompletion({ 
                self.requestUsersViaDataStoreWithCompletion({ 
                    
                })
            })
        }
}

Each request fetch an users. First and last via IDataStore. Second via custom api. After each request I print number of properties for each user in response. Current result:

Number of properties 58
Number of properties 59
Number of properties 59

The last one should be “Number of properties 58”. But because of second request every new user has one extra property.

I removed from the project “Pods” folder and also removed “Secret key” and custom hostURL

CustomPropertyError.zip (22.69kB)

Andrey, we need to reproduce this problem with YOUR app, so you should give us an access to it. Please provide your app url to support@backendless.com.

Sent the url and secret key

What is the name of this additional property?

isFavorite

Do you have this property in your Users table?

No, I don’t

Then I suppose that your code adds this property somehow, please inspect it thoroughly. It is extremely unlikely that this property is added by Backendless server or Backendless SDK.

As you can see in example project I didn’t save the objects from request. The custom property is added into response on server side for only one api (“searchUsers” in example project). And I don’t known how I can affect on IDataStore response.

Here is the part of server code:

...

for (int i = 0; i < maxSize; i++) {
    String potentialFavorite = users.getData().get(i).getObjectId();
    String whereFavoriteClause = "fromUser.ObjectId = '" + currentUser.getObjectId() + "' AND toUser.ObjectId = '" + potentialFavorite + "'" + " AND isUndone = false";
    dataFavoritesQuery.setWhereClause(whereFavoriteClause);
    BackendlessCollection&lt;Favorites&gt; favorites = Backendless.Data.of(Favorites.class).find(dataFavoritesQuery);
    if (favorites.getTotalObjects() > 0) {
        users.getData().get(i).setProperty("isFavorite", true);
    } else {
        users.getData().get(i).setProperty("isFavorite", false);
    }
} 

...

In your original question you said:

After that I cannot save "BackendlessUser" object because of that property, I get error "Unable to update user. Dynamic properties are disabled for this version of the application"

Where do you call the “save” method in your code?

Yes, eventually the additional property only affects on saving, since I have disabled “Enable Dynamic User Definition” and try to save an object with the property. I can add to example project a test save method, but I don’t understand how it will help. Also I don’t think my main app affects somehow on example project because if I restart the app (or example app) I receive objects without the property until I call custom api method.

Andrew,
you can either add some additional check before saving or create a simple test project that clearly demonstrates the error and send it at support@backendless.com

Andrey, by design all new object properties, which were retrieved from the server, are added to class - and then you cannot remove it. So yes - when you add a property isFavorite in the fetching result it is added to class as a property. This is a bad practice. You shouldn’t add the properties which are absent in the table on the server.

OK, I understood. I’ll try some other ways to customize the response. Thank you.