Repository: OpenEnergyPlatform/oeplatform

Issue:
The user is not informed when keywords are automatically added to table tags
When confirming that a selection of tags should be added to a table the user-selected choice of tags is expanded by the table's keywords as tags.

Example:
Table had no tags. Add tags `MODEX` and `open_MODEX`.  

![grafik](https://user-images.githubusercontent.com/54852694/160797771-37e75023-b7bc-4fd7-846e-2dca80487a91.png)

Result: Tables Keywords were added as tags as well.

![grafik](https://user-images.githubusercontent.com/54852694/160798443-c759ffd5-ca3d-47bb-95f0-5856dc4a257b.png)

I'm not sure if this is intended behaviour. In my case, this resulted in additional work removing the tags and was perceived as flawed usability.



Discussion:
Hi @chrwm , this feature was introduced with the latest OEP version. The keywords are the metadata representation of the OEP table tags. This is the reason why we decided to synchronize them.  Currently, this "synchronization" is only triggered when the user adds new tags to the table via the OEP website. 
The behavior you observed is to be expected. The main problem is that we are currently in a transition phase where users will find that the old metadata keywords are added to table tags. Of course, the inevitable result is that keywords are not always desirable as tags. 
We are sorry for this, but the OEP is still under construction and with new features it can always lead to such problems due to the already active use of the OEP. I have suggested a manual migration of all existing keywords, but this has not yet been done due to time and resource constraints.

The user should at least be informed about the action performed. I will display an info that notifies the user when new tags are automatically added from the keywords.
Thanks for the clarification @jh-RLI. I agree that there should be at least a status message about what actually happened, e.g. _"New tags were automatically added to the table from the metadata keywords"_

Resolving patch:
diff --git a/dataedit/urls.py b/dataedit/urls.py
--- a/dataedit/urls.py
+++ b/dataedit/urls.py
@@ -22,7 +22,7 @@
         views.DataView.as_view(),
         name="view",
     ),
-    url(r"^tags/add/$".format(qual=pgsql_qualifier), views.add_table_tags),
+    url(r"^tags/add/$".format(qual=pgsql_qualifier), views.redirect_after_table_tags_updated),
     url(
         r"^view/(?P<schema>{qual})/(?P<table>{qual})/download$".format(
             qual=pgsql_qualifier
diff --git a/dataedit/views.py b/dataedit/views.py
--- a/dataedit/views.py
+++ b/dataedit/views.py
@@ -50,6 +50,7 @@
 from .metadata.__init__ import load_metadata_from_db
 import requests as req
 
+from django.contrib import messages
 
 session = None
 
@@ -351,7 +352,7 @@ def get_readable_table_names(schema):
         conn.close()
     return {r[0]: read_label(r[0], load_metadata_from_db(schema, r[0])) for r in res}
 
-
+  
 def get_readable_table_name(schema_name, table_name):
     """get readable table name from metadata
 
@@ -444,7 +445,6 @@ def find_tables(schema_name=None, query_string=None, tag_ids=None):
 
     return tables
 
-
 def listtables(request, schema_name):
     """
     :param request: A HTTP-request object sent by the Django framework
@@ -1376,8 +1376,6 @@ def process_oem_keywords(session, schema, table, tag_ids, removed_table_tag_ids,
         # md, error = actions.try_parse_metadata(table_oemetadata)
         # print(md, error)
 
-    
-
     # Keep, this are the tags that where added by the user via OEP website
     updated_oep_tags = [] 
     # this are OEM keywords that are new to the OEP tags
@@ -1421,6 +1419,7 @@ def process_oem_keywords(session, schema, table, tag_ids, removed_table_tag_ids,
         if tag_id is not None:
             add_existing_keyword_tag_to_table_tags(session, schema, table, tag_id)
     
+    
 
     table_oemetadata["keywords"] = updated_keywords
     return table_oemetadata
@@ -1469,9 +1468,18 @@ def add_table_tags(request):
     
     # TODO: reuse session from above?
     with engine.begin() as con:
-        actions.set_table_metadata(table=table, schema=schema, metadata=updated_oem_json, cursor=con)        
+        actions.set_table_metadata(table=table, schema=schema, metadata=updated_oem_json, cursor=con)     
+
+
+    messasge = messages.success(request, 'Please note that OEMetadata keywords and table tags are synchronized. When submitting new tags, you may notice automatic changes to the table tags on the OEP and/or the "Keywords" field in the metadata.')   
 
     
+    return render(request, 'dataedit/dataview.html', {"messages": messasge})
+
+
+def redirect_after_table_tags_updated(request):
+    add_table_tags(request)
+
     return redirect(request.META["HTTP_REFERER"])
 
 


Test patch: