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
188 stars 107 forks source link

Dimension/Hierarchy update errors #17

Closed dusherwo57 closed 7 years ago

dusherwo57 commented 7 years ago

Marius, I have been working with TM1PY this week. Much of the functionality is working, but I am getting odd, inconsistent results with dimension updates. I have one setup running PA Local (11.0.00000.918) under Windows 7. This is working. It works whether I run the Python scripts locally or on another PC. I have another setup running PA Local (11.0.00200.998) under Windows Server 2016, within a VM. Running the scripts gives the error "code":"278","message":"Cannot modify Attributes property during Hierarchy PATCH Running the scripts against 10.2.2 FP7 gives the error "code":"","message":"PATCH not supported on this resource!" The script I use is:

from Services.LoginService import LoginService
from Services.RESTService import RESTService
from Services.DimensionService import DimensionService
from Services.HierarchyService import HierarchyService
login = LoginService.native('admin', 'apple')
# address = '25.39.47.199'
# address = '10.0.0.202'
address = ''
# Connection to TM1. Needs IP, Port, Credentials, and SSL
with RESTService(ip=address, port=8010, login=login, ssl=False) as tm1_rest:
    dimension_service = DimensionService(tm1_rest)
    # get dimension
    dimension = dimension_service.get('model2')
    # get the default hierarchy of the dimension
    h = dimension.hierarchies[0]
    # create new random element name
    element_name = 'Test9'
    # add element to hierarchy
    h.add_element(element_name=element_name, element_type='Numeric')
    #h.edges.clear()
    # add edge to hierarchy
    h.add_edge('Total', element_name, 1000)

    #for parent, child in h.edges:
    #       print("Parent Name: {}, Component Name: {}".format(parent, child))
    #h.remove_edge('Total','K Series')
    # write Dimension back to TM1

    dimension_service.update(dimension)

I was hoping to raise this in the SDK forum but I believe that I would need to show the REST/ODATA calls, and I am not sure how to do this for PATCH. If you have any suggestions I would be very grateful. (I have tried SSL and so long as the setting matches the server all seems to be fine.)

MariusWirtz commented 7 years ago

Hi David,

thank you for the feedback! Kinda sounds like a bug in the TM1 REST API to me.

I can't replicate it on my local instance (FP 6). It runs without issues and the dimensionupdate is successfull. I will try to replicate it on the latest TM1 version.

If you want to see which exact request was rejected, try to activate the TM1 REST API Loggers.

Cheers,

Marius

dusherwo57 commented 7 years ago

Thanks! I'll have a go.

dusherwo57 commented 7 years ago

I found (eventually) IBM's technote on the loggers, at http://www-01.ibm.com/support/docview.wss?uid=swg22004711 With the logger enabled, on my 'working' environment I see 20048 [8] DEBUG 2017-07-25 12:22:43.369 TM1.HttpRequest PATCH /api/v1/Dimensions('model2')/Hierarchies('model2') 20048 [8] DEBUG 2017-07-25 12:22:43.404 TM1.HttpRequestBody {"Name": "model2", "Elements": [{"Name": "L Series 1.6 L Convertible", "Type": "Numeric"}, {"Name": "L Series 1.6 L Sedan", "Type": "Numeric"}, {"Name": "L Series 1.8 L Convertible", "Type": "Numeric"}, {"Name": "L Series 1.8 L Sedan", "Type": "Numeric"}, {"Name": "L Series 1.8 L Wagon", "Type": "Numeric"}, {"Name": "L Series 1.8 L Wagon 4WD", "Type": "Numeric"}, {"Name": "L Series 2.0 L Convertible", "Type": "Numeric"}, {"Name": "L Series 2.0 L Sedan", "Type": "Numeric"}, {"Name": "L Series 2.0 L Wagon", "Type": "Numeric"}, {"Name": "L Series 2.0 L Wagon 4WD", "Type": "Numeric"}, {"Name": "L Series 2.5 L Convertible", "Type": "Numeric"}, {"Name": "L Series 2.5 L Sedan", "Type": "Numeric"}, {"Name": "S Series 1.8 L Sedan", "Type": "Numeric"}, {"Name": "S Series 1.8 L Wagon", "Type": "Numeric"}, {"Name": "S Series 2.0 L Sedan", "Type": "Numeric"}, {"Name": "S Series 2.0 L Wagon", "Type": "Numeric"}, {"Name": "S Series 2.5 L Sedan", "Type": "Numeric"}, {"Name": "S Series 2.5 L Sedan 4WD", "Type": "Numeric"}, {"Name": "S Series 2.5 L Wagon", "Type": "Numeric"}, {"Name": "S Series 2.5 L Wagon 4WD", "Type": "Numeric"}, {"Name": "S Series 3.0 L Sedan", "Type": "Numeric"}, {"Name": "S Series 3.0 L Sedan 4WD", "Type": "Numeric"}, {"Name": "S Series 3.0 L Wagon", "Type": "Numeric"}, {"Name": "S Series 3.0 L Wagon 4WD", "Type": "Numeric"}, {"Name": "S Series 3.4 L Sedan", "Type": "Numeric"}, {"Name": "S Series 3.4 L Sedan 4WD", "Type": "Numeric"}, {"Name": "S Series 3.4 L Wagon", "Type": "Numeric"}, {"Name": "S Series 3.4 L Wagon 4WD", "Type": "Numeric"}, {"Name": "T Series 2.8 L Coupe", "Type": "Numeric"}, {"Name": "T Series 2.8 L Sedan", "Type": "Numeric"}, {"Name": "T Series 3.2 L Coupe", "Type": "Numeric"}, {"Name": "T Series 3.2 L Sedan", "Type": "Numeric"}, {"Name": "T Series 4.0 L Coupe", "Type": "Numeric"}, {"Name": "T Series 4.0 L Sedan", "Type": "Numeric"}, {"Name": "T Series 5.0 L Coupe", "Type": "Numeric"}, {"Name": "T Series 5.0 L Sedan", "Type": "Numeric"}, {"Name": "L Series 4WD", "Type": "Consolidated"}, {"Name": "L Series Convertible", "Type": "Consolidated"}, {"Name": "L Series Sedan", "Type": "Consolidated"}, {"Name": "L Series Wagon", "Type": "Consolidated"}, {"Name": "S Series 4WD", "Type": "Consolidated"}, {"Name": "S Series Sedan", "Type": "Consolidated"}, {"Name": "S Series Wagon", "Type": "Consolidated"}, {"Name": "T Series Coupe", "Type": "Consolidated"}, {"Name": "T Series Sedan", "Type": "Consolidated"}, {"Name": "L Series", "Type": "Consolidated"}, {"Name": "S Series", "Type": "Consolidated"}, {"Name": "T Series", "Type": "Consolidated"}, {"Name": "L Series 2WD", "Type": "Consolidated"}, {"Name": "S Series 2WD", "Type": "Consolidated"}, {"Name": "Total", "Type": "Consolidated"}, {"Name": "Test9", "Type": "Numeric"}], "Edges": [{"ParentName": "L Series 4WD", "ComponentName": "L Series 1.8 L Wagon 4WD", "Weight": 1}, {"ParentName": "L Series 4WD", "ComponentName": "L Series 2.0 L Wagon 4WD", "Weight": 1}, {"ParentName": "L Series Convertible", "ComponentName": "L Series 1.6 L Convertible", "Weight": 1}, {"ParentName": "L Series Convertible", "ComponentName": "L Series 1.8 L Convertible", "Weight": 1}, {"ParentName": "L Series Convertible", "ComponentName": "L Series 2.0 L Convertible", "Weight": 1}, {"ParentName": "L Series Convertible", "ComponentName": "L Series 2.5 L Convertible", "Weight": 1}, {"ParentName": "L Series Sedan", "ComponentName": "L Series 1.6 L Sedan", "Weight": 1}, {"ParentName": "L Series Sedan", "ComponentName": "L Series 1.8 L Sedan", "Weight": 1}, {"ParentName": "L Series Sedan", "ComponentName": "L Series 2.0 L Sedan", "Weight": 1}, {"ParentName": "L Series Sedan", "ComponentName": "L Series 2.5 L Sedan", "Weight": 1}, {"ParentName": "L Series Wagon", "ComponentName": "L Series 1.8 L Wagon", "Weight": 1}, {"ParentName": "L Series Wagon", "ComponentName": "L Series 2.0 L Wagon", "Weight": 1}, {"ParentName": "L Series Wagon", "ComponentName": "L Series 1.8 L Wagon 4WD", "Weight": 1}, {"ParentName": "L Series Wagon", "ComponentName": "L Series 2.0 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 2.5 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 3.0 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 3.4 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 2.5 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 3.0 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series 4WD", "ComponentName": "S Series 3.4 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 1.8 L Sedan", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 2.0 L Sedan", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 2.5 L Sedan", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 3.0 L Sedan", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 3.4 L Sedan", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 2.5 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 3.0 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series Sedan", "ComponentName": "S Series 3.4 L Sedan 4WD", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 1.8 L Wagon", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 2.0 L Wagon", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 2.5 L Wagon", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 3.0 L Wagon", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 3.4 L Wagon", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 2.5 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 3.0 L Wagon 4WD", "Weight": 1}, {"ParentName": "S Series Wagon", "ComponentName": "S Series 3.4 L Wagon 4WD", "Weight": 1}, {"ParentName": "T Series Coupe", "ComponentName": "T Series 2.8 L Coupe", "Weight": 1}, {"ParentName": "T Series Coupe", "ComponentName": "T Series 3.2 L Coupe", "Weight": 1}, {"ParentName": "T Series Coupe", "ComponentName": "T Series 4.0 L Coupe", "Weight": 1}, {"ParentName": "T Series Coupe", "ComponentName": "T Series 5.0 L Coupe", "Weight": 1}, {"ParentName": "T Series Sedan", "ComponentName": "T Series 2.8 L Sedan", "Weight": 1}, {"ParentName": "T Series Sedan", "ComponentName": "T Series 3.2 L Sedan", "Weight": 1}, {"ParentName": "T Series Sedan", "ComponentName": "T Series 4.0 L Sedan", "Weight": 1}, {"ParentName": "T Series Sedan", "ComponentName": "T Series 5.0 L Sedan", "Weight": 1}, {"ParentName": "L Series", "ComponentName": "L Series Sedan", "Weight": 1}, {"ParentName": "L Series", "ComponentName": "L Series Wagon", "Weight": 1}, {"ParentName": "L Series", "ComponentName": "L Series Convertible", "Weight": 1}, {"ParentName": "S Series", "ComponentName": "S Series Sedan", "Weight": 1}, {"ParentName": "S Series", "ComponentName": "S Series Wagon", "Weight": 1}, {"ParentName": "T Series", "ComponentName": "T Series Sedan", "Weight": 1}, {"ParentName": "T Series", "ComponentName": "T Series Coupe", "Weight": 1}, {"ParentName": "L Series 2WD", "ComponentName": "L Series 4WD", "Weight": -1}, {"ParentName": "L Series 2WD", "ComponentName": "L Series", "Weight": 1}, {"ParentName": "S Series 2WD", "ComponentName": "S Series 4WD", "Weight": -1}, {"ParentName": "S Series 2WD", "ComponentName": "S Series", "Weight": 1}, {"ParentName": "Total", "ComponentName": "S Series", "Weight": 1}, {"ParentName": "Total", "ComponentName": "L Series", "Weight": 1}, {"ParentName": "Total", "ComponentName": "T Series", "Weight": 1}, {"ParentName": "Total", "ComponentName": "Test9", "Weight": 1000}]} 20048 [8] DEBUG 2017-07-25 12:22:43.410 TM1.HttpResponse 200 OK and on the 10.2.2 version I see 17944 [2401] DEBUG 2017-07-25 12:17:55.945 TM1.HttpRequest PATCH /api/v1/Dimensions('model2')/Hierarchies('model2') 17944 [2401] DEBUG 2017-07-25 12:17:56.010 TM1.HttpRequestBody {" 17944 [2401] DEBUG 2017-07-25 12:17:56.011 TM1.HttpResponse 400 Bad Request At first this suggested a problem with the setup of the python classes - but I am running the code from the same PC, just changing the address! I think I have enough to post on the SDK forum.

dusherwo57 commented 7 years ago

Update - the FP7 install is now working! PA 2.02 is not, PA 2.01 is. I shall do a rather different SDK forum post.

dusherwo57 commented 7 years ago

I have narrowed it down, I believe, to version issues. 10.2.2 FP7 is fine. Worryingly PA 2.02 is not. I have posted on the SDK forum: https://www.ibm.com/developerworks/community/forums/html/topic?id=75f2b99e-6961-4c71-9364-1d5e1e083eff&ps=25

I have now moved on to using the API to apply functions such is IRR which are not builtin to TM1. Looks quite promising, based on your DataFrame sample. Haven't yet written back the result. The calculations agree with Excel.

David Usherwood | Associate InfoCat, Riverside House, 27/29 Vauxhall Grove, London, SW8 1SY p: 020 7735 7711 | f: 020 7735 8811 www.infocat.co.uk This message is private and confidential. If you have received this message in error, please notify us and remove it from your system. InfoCat Ltd. is a limited company registered in England. Registered number:

  1. Registered office: 27-29 Vauxhall Grove, London, SW8 1SY.

IBM releases Planning Analytics Local, the new face of TM1. On Cloud, On Premises - YOU decide. Click here to find out more.

From: Marius Wirtz notifications@github.com To: MariusWirtz/TM1py TM1py@noreply.github.com Cc: dusherwo57 davidu@infocat.co.uk, Author author@noreply.github.com Date: 24/07/2017 21:40 Subject: Re: [MariusWirtz/TM1py] Dimension/Hierarchy update errors (#17)

Hi David, thank you for the feedback! Kinda sounds like a bug in the TM1 REST API to me. I can't replicate it on my local instance (FP 6). It runs without issues and the dimensionupdate is successfull. I will try to replicate it on the latest TM1 version. If you want to see which exact request was rejected, try to activate the TM1 REST API Loggers. Cheers, Marius — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

MariusWirtz commented 7 years ago

Calculating the IRR sounds like an interesting use case! Would you push it to the Samples?

dusherwo57 commented 7 years ago

When I have it working, sure.

Sent from my iPhone

David Usherwood | Associate InfoCat, Riverside House, 27/29 Vauxhall Grove, London, SW8 1SY p: 020 7735 7711 | f: 020 7735 8811 www.infocat.co.uk This message is private and confidential. If you have received this message in error, please notify us and remove it from your system. InfoCat Ltd. is a limited company registered in England. Registered number:

  1. Registered office: 27-29 Vauxhall Grove, London, SW8 1SY.

IBM releases Planning Analytics Local, the new face of TM1. On Cloud, On Premises - YOU decide. Click here to find out more.

On 27 Jul 2017, at 18:33, Marius Wirtz notifications@github.com wrote:

Calculating the IRR sounds like an interesting use case! Would you push it to the Samples?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.