cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
184 stars 107 forks source link

How is check_rules supposed to work? #277

Closed marfrit closed 3 years ago

marfrit commented 3 years ago

Describe what did you try to do with TM1py

kube.rules = "SKIPCHECK" (missing semicolon)
tm1.cubes.update(kube)
res = tm1.cubes.check_rules(kube.name)
print(res)

replies Response [201] (created)

Describe what's not working the way you expect Didn't get the expected result? Describe:

  1. The result you expected. An error message that the rules are invalid.

  2. A clear and concise description of what you are trying to do. Checking rules before uploading them from an Azure DevOps pipeline to TM1.

Version

Am I doing something wrong, or is this not working in the REST API?

MariusWirtz commented 3 years ago

Hi @marfrit,

I have to admit this part of TM1py is not so well designed.

the Response 201 in the console is the string representation of a Response object from the requests library Inside this object, you find the information you are looking for.

This code:

response = tm1.cubes.check_rules("WrongWithIllegalRule")
response_json = response.json()
print(response_json)

Produces this: {'@odata.context': '../$metadata#Collection(ibm.tm1.api.v1.RuleSyntaxError)', 'value': [{'LineNumber': 8, 'Message': 'Syntax error on or before: "\n[\'Bike Shares Measur\n missing semicolon " '}]}

I think we need to make this part of TM1py more accessible. Instead of returning the raw response, we could return two arguments:

return success, errors

Would that make more sense from a TM1py consumer perspective?

@pbuncik I noticed, that you added the check_rules function to TM1py initially (15891b50e04dbe80014d619ea5129c2313a7d210). Are you OK if we change it according to the sample above?

I will create a MR for it.

marfrit commented 3 years ago

For the compile method of the process service, I check if the response size is greater than zero and of yes, stop the pipeline. I guess I never thought about that not being encapsulated "enough".

Your reply helps a lot. I can't give any good suggestions, since I can write python code that does what I need, but I can't really write clean python.

MariusWirtz commented 3 years ago

Hi,

I see. I will change the method so that it behaves in line with the compile method. When there are errors in the rule, you will get a list of errors. If the rule is fine you will get en empty list.