<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="EN-US" link="#0563C1" vlink="#954F72"><div class="WordSection1"><p class="MsoNormal">Hi,</p><p class="MsoNormal"> </p><p class="MsoNormal">I’m currently working on developing a plugin to support build artifacts with custom metadata. I’d like to know if there is a way to update or replace an existing content unit. There are some use cases we’ve identified where we want to replace a previous content unit that has the same unit key. This might be a rare case, and the obvious alternative is to delete the existing content unit before starting the new upload. I was wondering if there was a way to handle this during the second upload? In the Importer upload_unit function, I noticed from other plugin examples that NotUniqueError exceptions are handled by re-associating the old content unit. I might be interpreting that incorrectly. If that’s the case, most of our re-upload attempts would fail silently, and the old data would remain. Can someone help me find a way to replace, or update an existing content unit that has an identical unit key, preferably during the upload/import process?</p><p class="MsoNormal"> </p><p class="MsoNormal">Here is the relevant plugin code that tries to import/associate a new content unit.</p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">        try:</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            artifact = models.Artifact.from_file(file_path, metadata)</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            artifact.save_and_import_content(file_path)</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            repo_controller.associate_single_unit(repo.repo_obj, artifact)</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">        except NotUniqueError:</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            artifact = artifact.__class__.objects.get(**artifact.unit_key)</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            repo_controller.associate_single_unit(repo.repo_obj, artifact)</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">        except Exception as e:</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">            return {'success_flag': False, 'summary': e.message, 'details': {}}</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas">        return {'success_flag': True, 'summary': '', 'details': {}}</span></b></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:Consolas"> </span></b></p><p class="MsoNormal">Jay</p></div></body></html>