Hi, I would change the Asset query from .one() to .first() if you leave .one() it will complain that the Asset doesn't exist (ftrack_api.exception.NoResultFoundError), setting it to .first() will return None which will properly trigger your if not asset: code block. There should only be one Asset with the same name under the same parent so .first() should work just fine. If you still need to set the version numbers yourself (at times we do that to make sure that the version has the same number that the component published) and you want to avoid duplicate errors, much like what you did with the Asset, you can query the AssetVersion with the specific version number under the same asset and see if it returns a value. If it does you could either notify the user that a previous version exist, and perhaps as if overwriting is desired (this can be dangerous but useful at times).
As a side note, on the code you provided you are setting the value of asset_version the first time to a query that returns the first entry it finds under the asset, than overriding it with a new AssetVersion entity you create.