Setting project tags in v12 seems oddly difficult

info-rchitect
info-rchitect Registered Posts: 186 ✭✭✭✭✭✭

HI,

It is very easy to get a list of the tags for a project but the set_tags function expects a dictionary. I created a dictionary (mydict) as so:

{'BAC': {'color': '#1ac2ab'}, 'ABC': {'color': '#1ac2ab'}, 'POO': {'color': '#1ac2ab'}}


I then use set_tags(mydict) which does not work but does not error.

Any ideas?

thx

Operating system used: Windows 10

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,089 Neuron

    Please post your Python code in a code block.

  • info-rchitect
    info-rchitect Registered Posts: 186 ✭✭✭✭✭✭
    import dataiku
    
    client = dataiku.api_client()
    project = client.get_project('myprojectkey') mytags = ['taga', 'tagb'] tags_dict = {}
    for tag in tags:
    if tag not in tags_dict:
    tags_dict[tag] = {}
    tags_dict[tag]['color'] = '#1ac2ab' # Copied this value from existing tags dict project.set_tags(tags_dict)

    thx much

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,089 Neuron
    edited November 3

    You got confused there. The set_tags() method is meant to be used in conjunction with the list_tags() method which is part of DSSProjectGit class and relates to Git tags not Project tags. Use the set_metadata() method to set project tags:

    import dataiku
    client = dataiku.api_client()
    project = client.get_default_project()
    
    project_metadata = project.get_metadata()
    print(project_metadata['tags'])
    project_metadata['tags'] = ['Tag1']
    project.set_metadata(project_metadata)
    project_metadata = project.get_metadata()
    print(project_metadata['tags'])
    

  • info-rchitect
    info-rchitect Registered Posts: 186 ✭✭✭✭✭✭

    @Turribeach Thanks for the explanation and the code. I checked the docs you sent and there is no description about the type of tags being referred to, as the set_tags function refers to the `dataikuapi.dss.project.DSSProject` class. Because that class has Github tags and internal tags, specifying the type in the function description would be good. Would it be reasonable to say an update in the documentation is value-add?

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,089 Neuron

    It's pretty clear to me. set_tags clearly says ":param dict tags: must be a modified version of the object returned by list_tags" and if you look at list_tags() it's part of the DSSProjectGit class. Do raise the Product enhancement if you want, but from my experience this sort of documentation clarifications never get implemented.

  • info-rchitect
    info-rchitect Registered Posts: 186 ✭✭✭✭✭✭

    The functions are not listed next to each other, as you show, and they don't belong to the same Class. list_tags is the only function that references anything related to Github. Just pointing out that searching for get_tags would provide no information on the type of tags being discussed (Dataiku or Github). Anyways, thx for the code, it works as expected.

Setup Info
    Tags
      Help me…