encode / databases

Async database support for Python. 🗄
https://www.encode.io/databases/
BSD 3-Clause "New" or "Revised" License
3.81k stars 260 forks source link

Not define the name of the application via DSN "application_name=my_app_name" #236

Open evgmoskalenko opened 4 years ago

evgmoskalenko commented 4 years ago

Hello, Could you tell me please, why I can't add application_name via DSN?

My DSN looks like:

from databases import Database

dsn = (
  f'postgresql://{user_name}:{password}'
  f'@{host}:{port}/{my_db_name}'
  f'?application_name=my_app_name'
)

db = Database(dsn)

Version:

vmarkovtsev commented 4 years ago

Hi! Easy-peasy. https://github.com/encode/databases/blob/master/databases/backends/postgres.py#L43

The workaround is to Database(dsn, **kwargs) and dsn.rsplit("&?").

evgmoskalenko commented 4 years ago

Thanks.. I Try. :-)

kuthair commented 3 months ago

Hello,

You can set application_name like this when creating the Database object:

_database = Database(DATABASE_URL, server_settings={'application_name': '<YOUR_APP_NAME>'})

This works, at least if you're using asyncpg library.

I found this in one of their issues: https://github.com/MagicStack/asyncpg/issues/798

Happy coding! =)