influxdb-python icon indicating copy to clipboard operation
influxdb-python copied to clipboard

`client.switch_database('db_name')` works, despite database not existing

Open newskooler opened this issue 5 years ago • 1 comments

  • InfluxDB version: '1.7.8'
  • InfluxDB-python version: 5.2.3
  • Python version: 3.7.7
  • Operating system version: Ubuntu 18.04.3 LTS

when I initialize a client like so:

client = InfluxDBClient(host=host, port=port, username=username, password=password) and then, if I want to write to a particular database, I would do: client.switch_database('some_db_name').

If some_db_name does not exist in client.get_list_database() I don't get any error. Also, a new db is not created either. It feels that it should at least give an early warning if not an error.

In addition:

  1. When I create a database that already exists, nothing happens (no warning or error). Therefore the question is, did it do nothing or did it create (overwrite) an existing one?
  2. It will be nice to have a function to show which database is the client currently on. There is no way of knowing currently (only via accessing the protected client._database.

newskooler avatar Apr 03 '20 23:04 newskooler

@snenkov thanks for the issue:

It looks like switch_database doesn't run any command against Influx: https://github.com/influxdata/influxdb-python/blob/master/influxdb/influxdb08/client.py#L173

  1. This is the behavior of InfluxDB: https://docs.influxdata.com/influxdb/v1.7/query_language/database_management/#create-database
  2. Feels like a very easy function to add to the client.py above. Would you like to take a crack at it?

russorat avatar Apr 13 '20 21:04 russorat