python-consul icon indicating copy to clipboard operation
python-consul copied to clipboard

query can not be executed by ID

Open Oh-noodles opened this issue 7 years ago • 1 comments

I created a query, and recorded it's ID. queryId = c.query.creat('TestService-service', name='testQuery')['ID'] but when I attempt to execute this query by ID,it raised a ConsulException. raise ConsulException("%d %s" % (response.code, response.body)) consul.base.ConsulException: 500 prepared query templates can only be resolved up by name, not by ID then I checked the python-consul doc, and it says that it could be executed by ID. image so does the Consul API website. image is this a bug, or a new feature?

Oh-noodles avatar Mar 15 '18 10:03 Oh-noodles

well, I found out,the query I created is a template. image the left is a query created by HTTP API, which could be executed by ID. and the right is the query created by python-consul API, and could not be executed by ID.

the difference is the value of type.

then I noticed that both the python-consul doc and Consul API website said the name_prefix_match is the only option for type. image image then I read the code and confirmed it's actually not configurable.

data = dict([
                (k, v) for k, v in {
                    'name': name,
                    'session': session,
                    'token': token or self.agent.token,
                    'dns': {
                        'ttl': ttl
                    } if ttl is not None else None,
                    'template': dict([
                        (k, v) for k, v in {
                            'type': 'name_prefix_match',
                            'regexp': regexp
                        }.items() if v is not None
                    ]),
                    'service': service_body
                }.items() if v is not None
            ]

then I modified the code and set the value of type to empty string, and it could be executed by ID now.

so, is this a bug? should the default value of type be empty string?

Oh-noodles avatar Mar 16 '18 07:03 Oh-noodles