Repository: rucio/rucio

Issue:
Trying to set is_new on dataset crashes
Motivation
----------
Making the following client call:

`client.set_metadata(scope='cms', name=did, key='is_new', value=True)
`

results in a crash of the server:

```
Traceback (most recent call last):
   File "/usr/lib/python2.7/site-packages/rucio/web/rest/did.py", line 703, in POST
     issuer=ctx.env.get('issuer'), recursive=recursive, vo=ctx.env.get('vo'))
   File "/usr/lib/python2.7/site-packages/rucio/api/did.py", line 421, in set_metadata
     return did.set_metadata(scope=scope, name=name, key=key, value=value, recursive=recursive)
   File "/usr/lib/python2.7/site-packages/rucio/db/sqla/session.py", line 377, in new_funct
     result = function(*args, **kwargs)
   File "/usr/lib/python2.7/site-packages/rucio/core/did.py", line 1241, in set_metadata
     did_meta_plugins.set_metadata(scope=scope, name=name, key=key, value=value, recursive=recursive, session=session)
   File "/usr/lib/python2.7/site-packages/rucio/core/did_meta_plugins/__init__.py", line 103, in set_metadata
     meta_handler.set_metadata(scope, name, key, value, recursive, session=session)
   File "/usr/lib/python2.7/site-packages/rucio/db/sqla/session.py", line 393, in new_funct
     result = function(*args, **kwargs)
   File "/usr/lib/python2.7/site-packages/rucio/core/did_meta_plugins/json_meta.py", line 85, in set_metadata
     raise NotImplementedError

```

This seems to be a regression since this definitely worked before. It seems as if an exception is being thrown because we're not supporting JSON metadata even though this is not JSON metadata. 

The CLI command set-metadata fails with the same error

Modification
------------





Discussion:
As mentioned on Slack, I think it should be sufficient to add this here
https://github.com/rucio/rucio/blob/51b45d74817e8acbaf75e3fe80f0c9270d9b0a0a/lib/rucio/core/did_meta_plugins/did_column_meta.py#L51
Should be added to `1.24.0` (rc2?) and a hotfix `1.23.11.post3` release.

Resolving patch:
diff --git a/lib/rucio/core/did_meta_plugins/did_column_meta.py b/lib/rucio/core/did_meta_plugins/did_column_meta.py
--- a/lib/rucio/core/did_meta_plugins/did_column_meta.py
+++ b/lib/rucio/core/did_meta_plugins/did_column_meta.py
@@ -15,7 +15,7 @@
 #
 # Authors:
 # - Vincent Garonne <vgaronne@gmail.com>, 2013-2018
-# - Martin Barisits <martin.barisits@cern.ch>, 2013-2019
+# - Martin Barisits <martin.barisits@cern.ch>, 2013-2020
 # - Cedric Serfon <cedric.serfon@cern.ch>, 2013-2020
 # - Ralph Vigne <ralph.vigne@cern.ch>, 2013
 # - Mario Lassnig <mario.lassnig@cern.ch>, 2013-2019
@@ -81,6 +81,7 @@
     "is_archive",
     "constituent",
     "access_cnt",
+    "is_new",
 
     # Keys used while listing dids
     "created_before",


Test patch:
diff --git a/lib/rucio/tests/test_meta_did.py b/lib/rucio/tests/test_meta_did.py
--- a/lib/rucio/tests/test_meta_did.py
+++ b/lib/rucio/tests/test_meta_did.py
@@ -1,4 +1,5 @@
-# Copyright 2012-2020 CERN for the benefit of the ATLAS collaboration.
+# -*- coding: utf-8 -*-
+# Copyright 2012-2020 CERN
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,6 +17,7 @@
 # - Vincent Garonne <vincent.garonne@cern.ch>, 2012-2014
 # - Mario Lassnig <mario.lassnig@cern.ch>, 2013-2017
 # - Benedikt Ziemons <benedikt.ziemons@cern.ch>, 2020
+# - Martin Barisits <martin.barisits@cern.ch>, 2020
 
 import unittest
 
@@ -56,3 +58,15 @@ def test_add_list_meta(self):
         meta = self.did_client.get_metadata(scope=tmp_scope, name=tmp_dataset)
         assert key in meta
         assert meta[key] == value
+
+    def test_set_is_new_meta(self):
+        """ META DID (CLIENTS):  Try to set is_new metadata"""
+        # Add a scope
+        tmp_scope = 'mock'
+
+        # Add a dataset
+        tmp_dataset = 'dsn_%s' % uuid()
+
+        self.did_client.add_dataset(scope=tmp_scope, name=tmp_dataset)
+
+        self.did_client.set_metadata(scope=tmp_scope, name=tmp_dataset, key='is_new', value=True)