diff --git a/journals/views.py b/journals/views.py
index d110e2b10f38cc1e8285632dc99fb4b75c1e0f31..bd3272c97cd433da914244bd1a933cfc46f6f257 100644
--- a/journals/views.py
+++ b/journals/views.py
@@ -1084,13 +1084,14 @@ def generic_metadata_xml_deposit(request, **kwargs):
     """
     type_of_object = kwargs['type_of_object']
     object_id = int(kwargs['object_id'])
-    relation_to_published = _object.relation_to_published()
 
     if type_of_object == 'report':
         _object = get_object_or_404(Report, id=object_id)
     elif type_of_object == 'comment':
         _object = get_object_or_404(Comment, id=object_id)
 
+    relation_to_published = _object.relation_to_published()
+
     if not _object.doi_label:
         _object.create_doi_label()