Renaming tag folders via script

Any chance to rename a tag folder via scripting?
A specific function is not documented, so I’m analyzing a creative solution inspired by
system.tag.editTag(tagPath="MyTag", attributes={"Name": "MyNewTag"})

I’m trying with
system.tag.editTag(tagPath="MyTag", attributes={"fullPath": "MyNewPath"})
or
attributes={"Path": "MyNewPath"})
or
attributes={"path": "MyNewPath"})
with no luck.
Creating a new tag and removing the old one is not a good way, since I loose the tag history.

Any advice?
Thank you

Only thing I’ve found so far is your first solution

system.tag.editTag(tagPath="MyTag", attributes={"Name": "MyNewTag"})

and following that up with an update query. Example python script can be placed in Script Library and called after system.tag.editTag

def RenameTag(tag):
		#tag = {OldPath: 'Path/To/Tag',NewTagName: 'NewTag'}
		# renames 'Path/To/Tag' to 'Path/To/NewTag'
		err = None
		if not tag.get('OldPath'):
			err = 'OldPath not defined'
		elif not system.tag.exists(tag['OldPath']):
			err = 'OldPath Tag not found: ' + tag.get('OldPath')
		
		NewPath = '/'.join(tag['OldPath'].split('/')[:-1] + [tag['NewTagName']])
		
		if system.tag.exists(tag.get('NewPath')):
			err = 'Tag already exists: ' + tag.get('NewPath')
		if err:
			raise ValueError({'message':err})
		
		system.tag.editTag(tagPath=tag['OldPath'], attributes={'Name':tag['NewTagName']})
		system.db.runNamedQuery('api','RenameTagHistory',{'OldPath':tag['OldPath'], 'NewPath':NewPath})

and the NamedQuery RenameTagHistory (in the ‘api’ project):
Parameters:
QueryString | OldPath | String
QueryString | NewPath | String
Query:

update [dbo].[sqlth_te] 
SET tagpath = REPLACE(tagpath,
					  LOWER('{OldPath}'),
					  LOWER('{NewPath}')
			  ) 
WHERE tagpath LIKE '{OldPath}%'

If you need to run this in the gateway scope, tag provider will need to be prepended to OldPath, and stripped back out before calling the runNamedQuery (sqlth_te table doesnt utilize tag provider in tagpath)

I have noticed issues with this method though, using attributes: {Name} to rename a folder or tag has odd results. Sometimes it renames the tag, sometimes it copies it, sometimes it renames it and everything underneath it disappears. I wouldn’t recommend it.