Skip to content

Commit ac3d3bc

Browse files
committed
Use error code to check for objects which already exists
1 parent 57aad48 commit ac3d3bc

File tree

6 files changed

+9
-124
lines changed

6 files changed

+9
-124
lines changed

samples/async/delete_ai_credential.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# -----------------------------------------------------------------------------
77

88
# -----------------------------------------------------------------------------
9-
# async/create_ai_credential.py
9+
# async/delete_ai_credential
1010
#
11-
# Async API to create credential
11+
# Async API to delete credential
1212
# -----------------------------------------------------------------------------
1313

1414
import asyncio

samples/delete_ai_credential.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# -----------------------------------------------------------------------------
99
# delete_ai_credential.py
1010
#
11-
# Create a Database credential storing OCI Gen AI's credentials
11+
# Delete AI credential
1212
# -----------------------------------------------------------------------------
1313
import os
1414

src/select_ai/admin.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/select_ai/async_profile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,14 @@ async def create(
218218
:return: None
219219
:raises: oracledb.DatabaseError
220220
"""
221+
if self.attributes is None:
222+
raise AttributeError("Profile attributes cannot be None")
221223
parameters = {
222224
"profile_name": self.profile_name,
223225
"attributes": self.attributes.json(),
224226
}
225227
if description:
226228
parameters["description"] = description
227-
228229
async with async_cursor() as cr:
229230
try:
230231
await cr.callproc(
@@ -234,7 +235,7 @@ async def create(
234235
except oracledb.DatabaseError as e:
235236
(error,) = e.args
236237
# If already exists and replace is True then drop and recreate
237-
if "already exists" in error.message.lower() and replace:
238+
if error.code == 20046 and replace:
238239
await self.delete(force=True)
239240
await cr.callproc(
240241
"DBMS_CLOUD_AI.CREATE_PROFILE",

src/select_ai/profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def create(self, replace: Optional[int] = False) -> None:
213213
except oracledb.DatabaseError as e:
214214
(error,) = e.args
215215
# If already exists and replace is True then drop and recreate
216-
if "already exists" in error.message.lower() and replace:
216+
if error.code == 20046 and replace:
217217
self.delete(force=True)
218218
cr.callproc(
219219
"DBMS_CLOUD_AI.CREATE_PROFILE",

src/select_ai/vector_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def create(self, replace: Optional[bool] = False):
192192
except oracledb.DatabaseError as e:
193193
(error,) = e.args
194194
# If already exists and replace is True then drop and recreate
195-
if "already exists" in error.message.lower() and replace:
195+
if error.code == 20048 and replace:
196196
self.delete(force=True)
197197
cr.callproc(
198198
"DBMS_CLOUD_AI.CREATE_VECTOR_INDEX",
@@ -399,7 +399,7 @@ async def create(self, replace: Optional[bool] = False) -> None:
399399
except oracledb.DatabaseError as e:
400400
(error,) = e.args
401401
# If already exists and replace is True then drop and recreate
402-
if "already exists" in error.message.lower() and replace:
402+
if error.code == 20048 and replace:
403403
await self.delete(force=True)
404404
await cr.callproc(
405405
"DBMS_CLOUD_AI.CREATE_VECTOR_INDEX",

0 commit comments

Comments
 (0)