You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/12/03 23:29:53 UTC

[GitHub] [incubator-superset] mistercrunch commented on a change in pull request #8712: guard against duplicate columns in datasource save

mistercrunch commented on a change in pull request #8712: guard against duplicate columns in datasource save
URL: https://github.com/apache/incubator-superset/pull/8712#discussion_r353478017
 
 

 ##########
 File path: superset/views/datasource.py
 ##########
 @@ -47,13 +51,29 @@ def save(self):
                 .filter(orm_datasource.owner_class.id.in_(datasource["owners"]))
                 .all()
             )
+
+        duplicates = [
+            name
+            for name, count in Counter(
+                [col["column_name"] for col in datasource["columns"]]
+            ).items()
+            if count > 1
+        ]
+        if duplicates:
+            return json_error_response(
+                f"Duplicate column name(s): {','.join(duplicates)}", status="409"
+            )
+
         orm_datasource.update_from_object(datasource)
         data = orm_datasource.data
         db.session.commit()
+
         return self.json_response(data)
 
     @expose("/get/<datasource_type>/<datasource_id>/")
     @has_access_api
+    @api
 
 Review comment:
   [outside the scope of this PR] we should sweep the code base for more places that could use `@api`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org