@@ -30,10 +30,17 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
3030 :param str, Organization org: specifies the organization for create the bucket;
3131 Take the ``ID``, ``Name`` or ``Organization``.
3232 If not specified the default value from ``InfluxDBClient.org`` is used.
33- :return: Bucket or the request thread when falling back.
33+ :return: Bucket
3434 If the method is called asynchronously,
35- returns also the request thread.
35+ returns the request thread.
3636 """
37+ if self ._buckets_service ._is_below_v2 ():
38+ # Fall back to v1 API if buckets are not supported
39+ warnings .warn ("InfluxDB versions below v2.0 are deprecated. " + \
40+ "Falling back to CREATE DATABASE statement" , DeprecationWarning )
41+ database_name = bucket_name if bucket_name is not None else bucket
42+ return self ._create_database (database = database_name )
43+
3744 if retention_rules is None :
3845 retention_rules = []
3946
@@ -55,19 +62,13 @@ def create_bucket(self, bucket=None, bucket_name=None, org_id=None, retention_ru
5562 client = self ._influxdb_client ,
5663 required_id = True ))
5764
58- try :
59- return self ._buckets_service .post_buckets (post_bucket_request = bucket )
60- except ApiException :
61- # Fall back to v1 API if buckets are not supported
62- database_name = bucket_name if bucket_name is not None else bucket
63- return self .create_database (database = database_name , retention_rules = retention_rules )
65+ return self ._buckets_service .post_buckets (post_bucket_request = bucket )
6466
65- def create_database (self , database = None , retention_rules = None ):
67+ def _create_database (self , database = None ):
6668 """Create a database at the v1 api (legacy).
6769
6870 :param database_name: name of the new database
69- :param retention_rules: retention rules array or single BucketRetentionRules
70- :return: Tuple (response body, status code, header dict)
71+ :return: tuple(response body, status code, header dict)
7172 """
7273 if database is None :
7374 raise ValueError ("Invalid value for `database`, must be defined." )
@@ -114,24 +115,26 @@ def delete_bucket(self, bucket):
114115 """Delete a bucket. Delete a database via v1 API as fallback.
115116
116117 :param bucket: bucket id or Bucket
117- :return: Bucket or the request thread when falling back
118+ :return: Bucket
118119 """
119120 if isinstance (bucket , Bucket ):
120121 bucket_id = bucket .id
121122 else :
122123 bucket_id = bucket
123124
124- try :
125- return self ._buckets_service .delete_buckets_id (bucket_id = bucket_id )
126- except ApiException :
127- return self .delete_database (database = bucket_id )
125+ if self ._buckets_service ._is_below_v2 ():
126+ # Fall back to v1 API if buckets are not supported
127+ warnings .warn ("InfluxDB versions below v2.0 are deprecated. " + \
128+ "Falling back to DROP DATABASE statement" , DeprecationWarning )
129+ return self ._delete_database (database = bucket_id )
128130
129- def delete_database (self , database = None ):
131+ return self ._buckets_service .delete_buckets_id (bucket_id = bucket_id )
132+
133+ def _delete_database (self , database = None ):
130134 """Delete a database at the v1 api (legacy).
131135
132136 :param database_name: name of the database to delete
133- :param retention_rules: retention rules array or single BucketRetentionRules
134- :return: Tuple (response body, status code, header dict)
137+ :return: tuple(response body, status code, header dict)
135138 """
136139 if database is None :
137140 raise ValueError ("Invalid value for `database`, must be defined." )
0 commit comments