How to handle record already exists insert error

If a record already exists, then inserting it will cause a 422 error. However, I’m confused on how to handle this error as it emits an “UnexpectedStatusCodeError”

In this Python code, how can I specifically catch record already exists errors? I tried checking the docs, but couldn’t find how to catch this one as I wish to not raise an exception when it occurs

try:
		tenant_collection = get_tenant_collection(tenant_name)
		
		uniqueid = tenant_collection.data.insert(
			vector=record.vector,
			properties=record.properties,
			uuid=record.uniqueid
		)

		return uniqueid
	except:
		# if already exists, wil throw 422 error
		print('Error in insert record')
		traceback.print_exc()
		raise Exception("Failed to insert record")

hi! @Tejas_Sharma !!!

Sorry, missed this message (last week was crazy).

Indeed this specific error get only a hint of what happened at the error message, and not raising a specific error.

I have questioned it with our team.

The best route here is to open a feature request at GitHub - weaviate/weaviate-python-client: A python native client for easy interaction with a Weaviate instance.

Thanks!

1 Like