cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Why are we enforced to use `is_*` methods of tagged union

Why are we enforced to use `is_*` methods of tagged union

rk90
Helpful | Level 5

I am trying to list all members in a column/row format.

For example, column1=email, column2=status

I can add email to the column1 row just fine, but I cannot access the status tag. I am enforced to call each is_* methods until I get a True response and then figure which is_* method returned True and the corresponding tag to the column2 row. Why can't we simply access the tag? Why this overhead of calling each is_* method and why not just add an attribute that returns the tag (I am reluctant to use the _tag attribute).

 

 

4 Replies 4

Greg-DB
Dropbox Staff

Thanks for the feedback! In general, the SDKs are meant to abstract away the concept of the "tag", but I'll pass this along as a feature request for a public accessor for the tag value itself. 

(Also, "_tag" is considered private, but that said, it's unlikely to change.)

rk90
Helpful | Level 5

I appreciate your response, Greg.

Please consider use cases where the value of the tag is necessary. For example, let's say I want to export all users/groups to a CSV file with column names that correspond to the tag names and rows that correspond to the value of the tag.

Columns: id, firstname, lastname, email, status

Rows: <id>, X, Y, x.y@noemail.com, <active|suspended>

In this case, I just need be to extract the value associated with `status` (i.e. user.status should either evaluate to 'active|suspended|removed'). This is unfortunately not possible with the current specification. Is there any other way to retrieve what I want?

Also, can you explain what following in the SDK implies? What are corresponding get_* methods here? I couldn't find any get_* methods.

This class acts as a tagged union. Only one of the is_* methods will return true. To get the associated value of a tag (if one exists), use the corresponding get_* method.

 

 

 

Greg-DB
Dropbox Staff

With the Python SDK, you can use the "_tag" property to access the value. It is private, and so not officially supported, but I don't expect it to change. Just make sure you test it whenver you update to a new version of the SDK.

The get_* methods can be used to retrieve the value of the set union field. The field may not always have a typed value to return, so you won't always see the get_* methods on any particular class. You can see an example of one at CreateFolderError.get_path though.

rk90
Helpful | Level 5

Thanks Greg!

I'm using a hacky approach to get the results. I wasn't confident using '_tag' attribute as it's private and implementation changes might break my code. 

 

 

 

Need more support?