faunadb-python
faunadb-python copied to clipboard
TypeError: catching classes that do not inherit from BaseException is not allowed
I'm creating cli application to interact with the db using typer and I've the following code:
# app.py
from typing import Any
from faunadb.client import FaunaClient
from faunadb import query as q
import typer
from .settings import get_settings
settings = get_settings()
client = FaunaClient(secret=settings.DB_ADMIN_PYTHON)
app = typer.Typer()
@app.command()
def create_collection_with_index(name: str) -> Any:
c = client.query(q.collection(name))
if client.query(q.exists(c)) == False:
c = client.query(q.create_collection({"name": name}))
idx_name = f"{name}_index"
ci = client.query(q.index(idx_name))
if client.query(q.exists(ci)) == False:
ci = client.query(
q.create_index(
{
"name": idx_name,
"unique": True,
"serialized": True,
"source": q.collection(name),
}
)
)
return c, ci
@app.command()
def initialize_db() -> None:
typer.echo("Initializing db...")
# app.py
from typing import Any
from faunadb.client import FaunaClient
from faunadb import query as q
import typer
from .settings import get_settings
settings = get_settings()
client = FaunaClient(secret=settings.DB_ADMIN_PYTHON)
app = typer.Typer()
@app.command()
def create_collection_with_index(name: str) -> Any:
c = client.query(q.collection(name))
if client.query(q.exists(c)) == False:
c = client.query(q.create_collection({"name": name}))
idx_name = f"{name}_index"
ci = client.query(q.index(idx_name))
if client.query(q.exists(ci)) == False:
ci = client.query(
q.create_index(
{
"name": idx_name,
"unique": True,
"serialized": True,
"source": q.collection(name),
}
)
)
return c, ci
@app.command()
def initialize_db() -> None:
typer.echo("Initializing db...")
uc, uci = create_collection_with_index(name="users")
bc, bci = create_collection_with_index(name="brokers")
dosc, dosci = create_collection_with_index(name="dos_paramters")
typer.echo("Db initialized...")
if __name__ == "__main__":
app()
typer.echo("Db initialized...")
if __name__ == "__main__":
app()
# settings.py
from pathlib import Path
from pydantic import BaseSettings
class Settings(BaseSettings):
DB_ADMIN_PYTHON: str
class Config:
env_file = ".env"
def get_settings() -> Settings:
try:
env_file: str = "./credentials/faunadb.env"
if Path(env_file).is_file():
envs = Settings(_env_file=env_file)
else:
envs = Settings()
return envs
except Exception as e:
raise e
When I run the application cli as python -m app:app initialize-db (note the - not as _ in the function declaration) I get the following errors after successful execution of the command:
(.venv) abbas@MKHM01:~/faunadb_base_exception$ python -m app.app initialize-db
Initializing db...
Db initialized...
Exception ignored in: <function FaunaClient.__del__ at 0x7f22cd3ba8b0>
Traceback (most recent call last):
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/faunadb/client.py", line 282, in __del__
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/requests/sessions.py", line 747, in close
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/requests/adapters.py", line 325, in close
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/poolmanager.py", line 222, in clear
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/_collections.py", line 100, in clear
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/poolmanager.py", line 173, in <lambda>
File "/faunadb_base_exception/.venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 494, in close
TypeError: catching classes that do not inherit from BaseException is not allowed
How can I resolve this issue?
To reproduce the issue clone repository After cloning use poetry install to get the environment setup.