Teradata / PyTd

A Python Module to make it easy to script powerful interactions with Teradata Database in a DevOps friendly way.
MIT License
108 stars 43 forks source link

Unstable "Invalid session mode" error while calling stored procedure #110

Closed H0bbitBaron closed 5 years ago

H0bbitBaron commented 5 years ago

Hello! I'm trying to call stored procedure with parameters on Teradata server from Linux server via python:

n=0
while True:
    try:
        n+=1
        with teradata.UdaExec().connect("${dataSourceName}") as session:
            session.callproc("SOMEDATABASE.SOMEPROCEDURE", params=['2018-08-01', '2018-08-31'])
        print(f"\rSuccess on {n}-th! ", end="", flush=True)
        break
    except:
        print(f"\r{n}-th error...", end="", flush=True)

and it works as a rule from 2-th time, but sometimes from 11-th and so on. Error is:

teradata.api.DatabaseError: (5510, '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database](-5510)Invalid session mode for procedure execution.')

My udaexec.ini:

# Application Configuration
[CONFIG]
appName=TDConnection
version=1
logConsole=False
dataSourceName=servername
table=DBC.DBCInfo 

# Default Data Source Configuration
[DEFAULT]
method=odbc
charset=UTF8

# Data Source Definition
[servername]
system=servername.domain.com
username=YYYYYY
password=XXXXXX

And full console log with error - https://pastebin.com/T3fwEcf0.

I suppose there is some timeout issue, but may be i'm wrong. Anyway, thank you in advance!

H0bbitBaron commented 5 years ago

@escheie sorry to bother you, can you please have a glance at this issue, may be you have some ideas?

escheie commented 5 years ago

First, I would only initialize teradata.UdaExec() once, outside the loop.

Second, that error message is coming from the Database and it means your sessions transaction mode is different than the transaction mode used to create the stored procedure. You can explicitly set the transactionMode of the session using "transactionMode" argument/property.

H0bbitBaron commented 5 years ago

First, I would only initialize teradata.UdaExec() once, outside the loop.

Second, that error message is coming from the Database and it means your sessions transaction mode is different than the transaction mode used to create the stored procedure. You can explicitly set the transactionMode of the session using "transactionMode" argument/property.

Yes, this helped! Thank you a lot. There can be 'Default', 'ANSI' and 'Teradata' modes. Solution for my conditions:

connect("${dataSourceName}", transactionMode='TERADATA')

P.S. Still wondering, why it worked using brute-force...