ChatterBot icon indicating copy to clipboard operation
ChatterBot copied to clipboard

Can't connect with SQLStorageAdapter on Oracle 11g

Open leandrohmvieira opened this issue 8 years ago • 5 comments

I'm trying the following:

bot = ChatBot('C-3PFO',
            storage_adapter="chatterbot.storage.SQLStorageAdapter",
            database_uri="oracle+cx_oracle://CHATBOT:Passcode@devserver:1521/devbase"
  			)

and got this error: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () 1 bot = ChatBot('C-3PFO', 2 storage_adapter="chatterbot.storage.SQLStorageAdapter", ----> 3
4 )

    D:\Python\Continuum\Anaconda3\lib\site-packages\chatterbot\chatterbot.py in __init__(self, name, **kwargs)
         37 
         38         self.logic = MultiLogicAdapter(**kwargs)
    ---> 39         self.storage = utils.initialize_class(storage_adapter, **kwargs)
         40         self.input = utils.initialize_class(input_adapter, **kwargs)
         41         self.output = utils.initialize_class(output_adapter, **kwargs)

    D:\Python\Continuum\Anaconda3\lib\site-packages\chatterbot\utils.py in initialize_class(data, **kwargs)
         31         Class = import_module(data)
         32 
    ---> 33         return Class(**kwargs)
         34 
         35 

    D:\Python\Continuum\Anaconda3\lib\site-packages\chatterbot\storage\sql_storage.py in __init__(self, **kwargs)
         75         )
         76 
    ---> 77         if not self.engine.dialect.has_table(self.engine, 'Statement'):
         78             self.create()
         79 

    D:\Python\Continuum\Anaconda3\lib\site-packages\sqlalchemy\dialects\oracle\base.py in has_table(self, connection, table_name, schema)
       1048     def has_table(self, connection, table_name, schema=None):
       1049         if not schema:
    -> 1050             schema = self.default_schema_name
       1051         cursor = connection.execute(
       1052             sql.text("SELECT table_name FROM all_tables "

    AttributeError: 'OracleDialect_cx_oracle' object has no attribute 'default_schema_name'

Looks like self.default_schema_name does not exist when the engine is created.

This same connection string works fine on SQLAlchemy, as this example code below is working:

from sqlalchemy import create_engine
string = "oracle+cx_oracle://CHATBOT:Passcode@devserver:1521/devbase"
engine = create_engine(string)
tables = engine.table_names()
print(tables)

Any advice on this matter would be a great help, thank in advance

leandrohmvieira avatar Feb 19 '18 17:02 leandrohmvieira

My guess could be you don't have Statement and Response tables weren't present your database, I don't know how to create them in or resync database. If you create those two tables then your problem might be resolved.

vkosuri avatar Feb 19 '18 17:02 vkosuri

@vkosuri I just created the tables manually on my schema(based on the tables created by SQLite) and just had the same error, it seems the engine dont know which schema to lookup to find them.

leandrohmvieira avatar Feb 19 '18 18:02 leandrohmvieira

Olá @leandrohmvieira Did you find a solution?

ferreira-guilherme avatar Apr 22 '20 21:04 ferreira-guilherme

@ferreira-guilherme no, I changed my Job and I left this problem there, they migrated the solution to Rasa

leandrohmvieira avatar Apr 23 '20 12:04 leandrohmvieira

As a work around I used a copy of sql_storage.py as a custom storage adapter, then just commented out lines 46 and 47 (below) if not self.engine.dialect.has_table(self.engine, 'Statement'): self.create_database()

callenbj avatar Jul 30 '21 21:07 callenbj