Forum Discussion

rk90's avatar
rk90
Helpful | Level 5
7 years ago

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

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

 

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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's avatar
      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox 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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 11 hours ago
352 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!