cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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: 

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

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

rk90
Explorer | Level 4

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

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

Greg-DB
Dropboxer

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

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

rk90
Explorer | Level 4

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.

 

 

 

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

Greg-DB
Dropboxer

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.

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

rk90
Explorer | Level 4

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. 

 

 

 

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    rk90 Explorer | Level 4
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?