ananthagopi9381 commented on issue #17704:
URL: https://github.com/apache/superset/issues/17704#issuecomment-1003870960
browser type and version:
superset version: 1.3.0
Python version: 3.8.2
any feature flags active: True
And the issue is when I am overwriting the slice name it should show a 412
error and after refreshing the page it will show the duplicate slice names
I had changed the code on the superset/views/core.py file
@api
@handle_api_exception
@has_access_api
@event_logger.log_this
@expose("/filter/<datasource_type>/<int:datasource_id>/<column>/")
def filter( # pylint: disable=no-self-use
self, datasource_type: str, datasource_id: int, column: str
) -> FlaskResponse:
"""
Endpoint to retrieve values for specified column.
:param datasource_type: Type of datasource e.g. table
:param datasource_id: Datasource id
:param column: Column name to retrieve values for
:returns: The Flask response
:raises SupersetSecurityException: If the user cannot access the
resource
"""
# TODO: Cache endpoint by user, datasource and column
datasource = ConnectorRegistry.get_datasource(
datasource_type, datasource_id, db.session,
)
if not datasource:
return json_error_response(DATASOURCE_MISSING_ERR)
datasource.raise_for_access()
payload = json.dumps(
datasource.values_for_column(column,
config["FILTER_SELECT_ROW_LIMIT"]),
default=utils.json_int_dttm_ser,
ignore_nan=True,
)
return json_success(payload)
@staticmethod
def remove_extra_filters(filters: List[Dict[str, Any]]) ->
List[Dict[str, Any]]:
"""Extra filters are ones inherited from the dashboard's temporary
context
Those should not be saved when saving the chart"""
return [f for f in filters if not f.get("isExtra")]
def save_or_overwrite_slice(
# pylint: disable=too-many-arguments,too-many-locals,no-self-use
self,
slc: Optional[Slice],
slice_add_perm: bool,
slice_overwrite_perm: bool,
slice_download_perm: bool,
datasource_id: int,
datasource_type: str,
datasource_name: str,
query_context: Optional[str] = None,
) -> FlaskResponse:
"""Save or overwrite a slice"""
slice_name = request.args.get("slice_name")
action = request.args.get("action")
form_data = get_form_data()[0]
slice_id = request.args.get("slice_id")
if action == "saveas":
if "slice_id" in form_data:
form_data.pop("slice_id") # don't save old slice_id
slc = Slice(owners=[g.user] if g.user else [])
form_data["adhoc_filters"] = self.remove_extra_filters(
form_data.get("adhoc_filters", [])
)
assert slc
slc.params = json.dumps(form_data, indent=2, sort_keys=True)
slc.datasource_name = datasource_name
slc.viz_type = form_data["viz_type"]
slc.datasource_type = datasource_type
slc.datasource_id = datasource_id
slc.last_saved_by = g.user
slc.last_saved_at = datetime.now()
slc.slice_name = slice_name
slc.query_context = query_context
if action == "saveas" and slice_add_perm:
print('Overwrite area', slice_id, '--------', slice_name)
overwrite_status = ChartDAO.validate_slice_uniqueness(slice_name)
print('Overwrite Status : ', overwrite_status)
if not overwrite_status:
#flash("Chart must b unq")
return json_error_response(
__(
" slice Name Must be unique . "
),
412,
)
else:
ChartDAO.save(slc)
msg = _("Chart [{}] has been saved").format(slc.slice_name)
flash(msg, "info")
elif action == "overwrite" and slice_overwrite_perm:
print('Overwrite area', slice_id, '--------', slice_name)
overwrite_status =
ChartDAO.validate_update_slice_name_uniqueness(slice_id, slice_name)
print('Overwrite Status : ', overwrite_status)
if not overwrite_status:
return json_error_response(
__(
"This slice name was same name. "
"slice name Must be Unique."
),
412,
)
else:
ChartDAO.overwrite(slc)
msg = _("Chart [{}] has been
overwritten").format(slc.slice_name)
flash(msg, "info")
else:
pass
# Adding slice to a dashboard if requested
dash: Optional[Dashboard] = None
save_to_dashboard_id = request.args.get("save_to_dashboard_id")
new_dashboard_name = request.args.get("new_dashboard_name")
if save_to_dashboard_id:
# Adding the chart to an existing dashboard
dash = cast(
Dashboard,
db.session.query(Dashboard)
.filter_by(id=int(save_to_dashboard_id))
.one(),
)
# check edit dashboard permissions
dash_overwrite_perm = check_ownership(dash, raise_if_false=False)
if not dash_overwrite_perm:
return json_error_response(
_("You don't have the rights to ")
+ _("alter this ")
+ _("dashboard"),
status=403,
)
flash(
_("Chart [{}] was added to dashboard [{}]").format(
slc.slice_name, dash.dashboard_title
),
"info",
)
elif new_dashboard_name:
# Creating and adding to a new dashboard
# check create dashboard permissions
dash_add_perm = security_manager.can_access("can_write",
"Dashboard")
if not dash_add_perm:
return json_error_response(
_("You don't have the rights to ")
+ _("create a ")
+ _("dashboard"),
status=403,
)
dash = Dashboard(
dashboard_title=request.args.get("new_dashboard_name"),
owners=[g.user] if g.user else [],
)
flash(
_(
"Dashboard [{}] just got created and chart [{}] was
added " "to it"
).format(dash.dashboard_title, slc.slice_name),
"info",
)
if dash and slc not in dash.slices:
dash.slices.append(slc)
db.session.commit()
response = {
"can_add": slice_add_perm,
"can_download": slice_download_perm,
"can_overwrite": is_owner(slc, g.user),
"form_data": slc.form_data,
"slice": slc.data,
"dashboard_url": dash.url if dash else None,
"dashboard_id": dash.id if dash else None,
}
if dash and request.args.get("goto_dash") == "true":
response.update({"dashboard": dash.url})
return json_success(json.dumps(response))
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]