I have a very simple API using flask_tryton. It was developed under Tryton 5.4, and we migrated to Tryton 6.0 on the production and testing servers, where it works perfectly.
However, on my local development environment, I am encountering an error and cannot start it.
Traceback (most recent call last):
File "/home/lims/src/api_flask/__init__.py", line 70, in <module>
tryton = Tryton(app)
File "/home/lims/src/venv_test/lib/python3.7/site-packages/flask_tryton.py", line 51, in __init__
self.init_app(app)
File "/home/lims/src/venv_test/lib/python3.7/site-packages/flask_tryton.py", line 66, in init_app
with Transaction().start(database, user, readonly=True):
File "/home/lims/src/venv_test/lib/python3.7/site-packages/trytond/transaction.py", line 107, in start
database = backend.Database(database_name).connect()
File "/home/lims/src/venv_test/lib/python3.7/site-packages/trytond/backend/sqlite/database.py", line 355, in connect
factory=SQLiteConnection)
sqlite3.OperationalError: unable to open database file
For the migration of my local development environment, a virtual environment with the same name as the old one was used to avoid changing any files.
I made sure that the Tryton configuration files /home/lims/src/trytond.conf and the config.cfg file used by flask_tryton are being read (by temporarily renaming the files, which triggered a specific error).
The error is raised because you are connecting to a Sqlite databse which does not exist.
This may be due to some issues:
If you have your database on postgresql, the server is not reading the proper config file, so it uses the default values (sqlite)
If your database is on postgres it may be created on the wrong path or does not exist. Make sure that a file named database.sqlite (where database is the name of yourdatabase) exists under the directory pointed by the [database]path value of your configuration. If you do not have any configuration setting, the database will be read from the db folderd in the home directory of the user running the server
Also make sure that the user running trytond has read permissions on the config files otherwise the file will be ignored.
In order to debug the problem, I will recommend running trytond with verbose flag as the server will print the configuration file used in such mode.
Esto funcionaba antes de pasar a Tryton 6.0 ()y en los serves de producción y testing funcionan, pero corren con gunicorn, en desarrollo local uso el servidorde desarrollo de flask. El contenido del__init__.py comienza acá:
-- coding: utf8 --
import os
from functools import wraps
from datetime import datetime, timedelta
from typing import List
from itertools import chain
from pydantic import BaseModel, ValidationError, validator
from trytond.model.modelstorage import RequiredValidationError
from trytond.transaction import Transaction
from flask import Flask, jsonify, request
from flask_cors import CORS
from flask_tryton import Tryton
Seguramente el problema es que no tienes la variable de entorno TRYTOND_CONFIG apuntando a tu fichero de configuración. Al no encontrar esta variable entonces coje los valores por defecto y por eso te esta intentando ejecutar el SQLite
Es como decías tuve que hacer en línea de comandos:
export TRYTOND_CONFIG=/home/lims/src/trytond.conf
y lo agregué al .bashrc.
Me confundió que no era necesario antes de hacer la migración de 5.4 a 6.0, y en los servidores de producción y testing no veo dónde está seteada esa variable (yo no hago la administración de los servidores).