Discussion:
[tryton] database initialization
Cato Nano
2018-01-31 13:34:50 UTC
Permalink
I run this line

trytond-admin -c ./trytond.conf -d tryton --all

Then I try to start Proteus like this

config = config.set_trytond(database='postgresql://tryton@/')

because I'd like to prod my methods with the same database tha I use when I' m in the client

But this is what I get

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-8-c8456c787960> in <module>()
----> 1 config = config.set_trytond(database='postgresql://tryton@/')

~/tributi/env/lib/python3.6/site-packages/proteus/config.py in set_trytond(database, user, config_file)
272 config_file=None):
273 'Set trytond package as backend'
--> 274 _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
275 return _CONFIG.current
276

~/tributi/env/lib/python3.6/site-packages/proteus/config.py in __init__(self, database, user, config_file)
219 database_name = uri.path.strip('/')
220 if not database_name:
--> 221 database_name = os.environ['DB_NAME']
222 self.database_name = database_name
223 self._user = user

~/tributi/env/lib64/python3.6/os.py in __getitem__(self, key)
667 except KeyError:
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
671

KeyError: 'DB_NAME'


I thought I passed the db URI as an argument. Why does the db name get searched as a n env var ?

How can I use Proteus with the same Postgres db that I use in the client rather than a sqlite one ?

Thanks
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/03f779bb-1a75-4bb1-9451-ffc639dcb7dc%40googlegroups.com.
Sergi Almacellas Abellana
2018-01-31 13:38:17 UTC
Permalink
Post by Cato Nano
I run this line
trytond-admin -c ./trytond.conf -d tryton --all
Then I try to start Proteus like this
because I'd like to prod my methods with the same database tha I use when I' m in the client
But this is what I get
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-8-c8456c787960> in <module>()
~/tributi/env/lib/python3.6/site-packages/proteus/config.py in set_trytond(database, user, config_file)
273 'Set trytond package as backend'
--> 274 _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
275 return _CONFIG.current
276
~/tributi/env/lib/python3.6/site-packages/proteus/config.py in __init__(self, database, user, config_file)
219 database_name = uri.path.strip('/')
--> 221 database_name = os.environ['DB_NAME']
222 self.database_name = database_name
223 self._user = user
~/tributi/env/lib64/python3.6/os.py in __getitem__(self, key)
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
671
KeyError: 'DB_NAME'
I thought I passed the db URI as an argument. Why does the db name get searched as a n env var ?
The uri you passed has no database name. The URI format is:

postgresql://user:***@host/database (all arguments are optional)

Proteus search for an environment variable called DB_NAME if no database
name is passed on the uri. You don't have this environment variable set.

So you have two options here:

1. Set DB_NAME environament variable with the database name to use.
2. Include the database name in the uri.

Hope it helps.
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/be837420-9af6-f89c-1374-e86afe36fde1%40koolpi.com.
Cato Nano
2018-01-31 17:08:42 UTC
Permalink
Post by Sergi Almacellas Abellana
Post by Cato Nano
I run this line
trytond-admin -c ./trytond.conf -d tryton --all
Then I try to start Proteus like this
because I'd like to prod my methods with the same database tha I use when I' m in the client
But this is what I get
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-8-c8456c787960> in <module>()
~/tributi/env/lib/python3.6/site-packages/proteus/config.py in set_trytond(database, user, config_file)
273 'Set trytond package as backend'
--> 274 _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
275 return _CONFIG.current
276
~/tributi/env/lib/python3.6/site-packages/proteus/config.py in __init__(self, database, user, config_file)
219 database_name = uri.path.strip('/')
--> 221 database_name = os.environ['DB_NAME']
222 self.database_name = database_name
223 self._user = user
~/tributi/env/lib64/python3.6/os.py in __getitem__(self, key)
668 # raise KeyError with the original key value
--> 669 raise KeyError(key) from None
670 return self.decodevalue(value)
671
KeyError: 'DB_NAME'
I thought I passed the db URI as an argument. Why does the db name get searched as a n env var ?
Proteus search for an environment variable called DB_NAME if no database
name is passed on the uri. You don't have this environment variable set.
1. Set DB_NAME environament variable with the database name to use.
2. Include the database name in the uri.
Hope it helps.
--
Sergi Almacellas Abellana
www.koolpi.com
thank you Sergi

my undertsanding of this is that with that connection string, the connection to postgres happens through some Unix socket, rather than a loopback tcp connection

That string is the one that's in my trytond.conf file and it works.

As a reference, you can see this answer, in which they suggest that you can omit the host when using a unix socket

https://stackoverflow.com/questions/27037990/connecting-to-postgres-via-database-url-and-unix-socket-in-rails

In order to debug I could use a loopback tcp thing, speed won' t be a concern in that case

it' s just that I' d love to feel like I have a grip on these issues
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/dc274b3d-ecae-4d06-8690-438f7994cabf%40googlegroups.com.
Cato Nano
2018-01-31 17:10:14 UTC
Permalink
more precisely, this is the string that is in my conf file

uri = postgresql://tryton@/
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/f1e10540-3e3f-4320-8f75-ae7023e541c1%40googlegroups.com.
Cato Nano
2018-01-31 17:20:48 UTC
Permalink
ok, this is what happens





In [2]: config = config.set_trytond('postgresql://tryton:***@localhost/tryton
...: ')
/home/catonano/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py:143: DeprecationWarning: This method will be removed in future versions. Use 'parser.read_file()' instead.
module_config.readfp(fp)
---------------------------------------------------------------------------
OperationalError Traceback (most recent call last)
<ipython-input-2-e34280afcb91> in <module>()
----> 1 config = config.set_trytond('postgresql://tryton:***@localhost/tryton')

~/tributi/env/lib/python3.6/site-packages/proteus/config.py in set_trytond(database, user, config_file)
272 config_file=None):
273 'Set trytond package as backend'
--> 274 _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
275 return _CONFIG.current
276

~/tributi/env/lib/python3.6/site-packages/proteus/config.py in __init__(self, database, user, config_file)
226 Pool.start()
227 self.pool = Pool(database_name)
--> 228 self.pool.init()
229
230 with Transaction().start(self.database_name, 0) as transaction:

~/tributi/env/lib/python3.6/site-packages/trytond/pool.py in init(self, update, lang, installdeps)
151 self._pool[self.database_name][type] = {}
152 restart = not load_modules(self.database_name, self, update=update,
--> 153 lang=lang, installdeps=installdeps)
154 if restart:
155 self.init()

~/tributi/env/lib/python3.6/site-packages/trytond/modules/__init__.py in load_modules(database_name, pool, update, lang, installdeps)
459
460 if not Transaction().connection:
--> 461 with Transaction().start(database_name, 0):
462 _load_modules(update)
463 else:

~/tributi/env/lib/python3.6/site-packages/trytond/transaction.py in start(self, database_name, user, readonly, context, close, autocommit, _nocache)
86 database = Database().connect()
87 else:
---> 88 database = Database(database_name).connect()
89 Flavor.set(Database.flavor)
90 self.user = user

~/tributi/env/lib/python3.6/site-packages/trytond/backend/postgresql/database.py in __new__(cls, name)
94 inst._connpool = ThreadedConnectionPool(
95 minconn, maxconn, cls.dsn(name),
---> 96 cursor_factory=LoggingCursor)
97
98 cls._databases[name] = inst

~/tributi/env/lib/python3.6/site-packages/psycopg2/pool.py in __init__(self, minconn, maxconn, *args, **kwargs)
159 import threading
160 AbstractConnectionPool.__init__(
--> 161 self, minconn, maxconn, *args, **kwargs)
162 self._lock = threading.Lock()
163

~/tributi/env/lib/python3.6/site-packages/psycopg2/pool.py in __init__(self, minconn, maxconn, *args, **kwargs)
56
57 for i in range(self.minconn):
---> 58 self._connect()
59
60 def _connect(self, key=None):

~/tributi/env/lib/python3.6/site-packages/psycopg2/pool.py in _connect(self, key)
60 def _connect(self, key=None):
61 """Create a new connection and assign it to 'key' if not None."""
---> 62 conn = psycopg2.connect(*self._args, **self._kwargs)
63 if key is not None:
64 self._used[key] = conn

~/tributi/env/lib/python3.6/site-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
128
129 dsn = _ext.make_dsn(dsn, **kwargs)
--> 130 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
131 if cursor_factory is not None:
132 conn.cursor_factory = cursor_factory

OperationalError: FATALE: nessuna voce in pg_hba.conf per l'host "::1", utente "tryton", database "tryton", SSL non abilitato
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/fe7404e3-f4dc-449c-8dc0-0b9e7a89b1b2%40googlegroups.com.
Cato Nano
2018-02-01 09:41:22 UTC
Permalink
Post by Cato Nano
more precisely, this is the string that is in my conf file
ok I configured postgres in a liberl way and I managed to find an uri string that works with proteus

I' d still love to be able to avoid using tcp connections, but that's a detail

Thanks
--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/31a74bc1-922d-44c2-82c3-a11b4ccec92e%40googlegroups.com.
Loading...