Repository: StackStorm/st2

Issue:
Tags filtering is not returning the expected result through the API
**ISSUE TYPE**

Bug Report

**STACKSTORM VERSION**

`st2 3.0dev (367e117), on Python 2.7.12`

**OS / ENVIRONMENT / INSTALL METHOD**

stackstorm-ha helm chart

**SUMMARY**

When trying to filter all the actions based on the tags field an empty list is returned.
For example with the following action definition.

```yaml
---
name: "restart"
runner_type: "local-shell-script"
description: "Restart Gameworld"
enabled: true
entry_point: "webistrano.py"
tags:
  - name: portal-visible
    value: "yes"
parameters:
  gameworld:
    type: "string"
    description: "Enter Gameworld"
    required: true
    position: 0
```

I get this response:

```
GET https://stackstorm/api/v1/actions?tags=portal-visible

HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Tue, 03 Dec 2019 16:36:29 GMT
Content-Type: application/json
Content-Length: 2
Connection: keep-alive
X-Total-Count: 0

[]

Response code: 200 (OK); Time: 97ms; Content length: 2 bytes
```


Discussion:
I just verified the bug with 
```
st2 --version
st2 3.1.0, on Python 2.7.6
```
in the st2-docker setup.

Curl to retrieve an action with a tag:
```
curl -H "X-Auth-Token: xxx" -k https://localhost/api/v1/actions?name=marvel_workflow_demo
[
    {
        "parameters": {
            "environment": {
                "required": true,
                "type": "string"
            },
            "component": {
                "required": true,
                "type": "string"
            },
            "docker_tag": {
                "required": true,
                "type": "string"
            }
        },
        "runner_type": "orquesta",
        "tags": [
            {
                "name": "marvel-project",
                "value": "self-service"
            }
        ],
        "description": "A basic workflow that applies the default workflow for docker image updates.",
        "enabled": true,
        "metadata_file": "actions/marvel_workflow_demo.meta.yaml",
        "entry_point": "workflows/marvel_workflow_demo.yaml",
        "notify": {},
        "output_schema": {},
        "uid": "action:cm_demo_pack:marvel_workflow_demo",
        "pack": "cm_demo_pack",
        "ref": "cm_demo_pack.marvel_workflow_demo",
        "id": "5e4c213b90f52c00e35343ea",
        "name": "marvel_workflow_demo"
    }
```

Curl with the tag filter: 
```
curl -H "X-Auth-Token: xxx" -k https://localhost/api/v1/actions?tags=marvel-project
[]
```

@winem Thanks for checking this issue! I assigned the respective tags, assuming it's verified bug.

Looks like tag filtering for the actions functionality was added in st2 `v2.9` via https://github.com/StackStorm/st2/pull/4219 contribution.
Ok, I was able to nail it down. The issue is that both tags have the same value as indicator:

https://github.com/NikosVlagoidis/st2/blob/3132f6ad72ca9188093b1dc067808efcc19e3d66/st2api/st2api/controllers/v1/actions.py#L61-L65 

Therefore, the tag filter just works if the tag value matches the name. 

Example to get the task from above: 
```
curl -H "X-Auth-Token: xxx" -k 'https://localhost/api/v1/actions?tags=marvel_workflow_demo'
[
    {
        "parameters": {
            "environment": {
                "required": true,
                "type": "string"
            },
            "component": {
                "required": true,
                "type": "string"
            },
            "docker_tag": {
                "required": true,
                "type": "string"
            }
        },
        "runner_type": "orquesta",
        "tags": [
            {
                "name": "marvel-project",
                "value": "self-service"
            }
        ],
        "description": "A basic workflow that applies the default workflow for docker image updates.",
        "enabled": true,
        "metadata_file": "actions/marvel_workflow_demo.meta.yaml",
        "entry_point": "workflows/marvel_workflow_demo.yaml",
        "notify": {},
        "output_schema": {},
        "uid": "action:cm_demo_pack:marvel_workflow_demo",
        "pack": "cm_demo_pack",
        "ref": "cm_demo_pack.marvel_workflow_demo",
        "id": "5e4c213b90f52c00e35343ea",
        "name": "marvel_workflow_demo"
    }
]
```

Resolving patch:
diff --git a/st2api/st2api/controllers/v1/actions.py b/st2api/st2api/controllers/v1/actions.py
--- a/st2api/st2api/controllers/v1/actions.py
+++ b/st2api/st2api/controllers/v1/actions.py
@@ -62,7 +62,7 @@ class ActionsController(resource.ContentPackResourceController):
     supported_filters = {
         'name': 'name',
         'pack': 'pack',
-        'tags': 'name'
+        'tags': 'tag.name'
     }
 
     query_options = {


Test patch: