Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when removing used druid datasource #1141

Closed
maver1ck opened this issue Sep 19, 2016 · 5 comments
Closed

Better error message when removing used druid datasource #1141

maver1ck opened this issue Sep 19, 2016 · 5 comments
Assignees
Labels
!deprecated-label:bug Deprecated label - Use #bug instead inactive Inactive for >= 30 days

Comments

@maver1ck
Copy link
Contributor

When I'm removing druid datasource which have some slice added I'm getting this error message:
General Error <class 'UnboundLocalError'>

I think it should be something more human readable.

Full stacktrace.

2016-09-19 22:09:37,496:ERROR:flask_appbuilder.models.sqla.interface:Delete record error: local variable 'src_class' referenced before assignment
Traceback (most recent call last):
  File "/home/mbrynski/.local/lib/python3.4/site-packages/Flask_AppBuilder-1.8.1-py3.4.egg/flask_appbuilder/models/sqla/interface.py", line 318, in delete
    self.session.commit()
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/scoping.py", line 157, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 801, in commit
    self.transaction.commit()
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 392, in commit
    self._prepare_impl()
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 372, in _prepare_impl
    self.session.flush()
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 2019, in flush
    self._flush(objects)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 2137, in _flush
    transaction.rollback(_capture_exception=True)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 60, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/util/compat.py", line 186, in reraise
    raise value
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/session.py", line 2101, in _flush
    flush_context.execute()
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 373, in execute
    rec.execute(self)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 532, in execute
    uow
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 149, in save_obj
    base_mapper, states, uowtransaction
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 282, in _organize_states_for_save
    mapper.dispatch.before_update(mapper, connection, state)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/event/attr.py", line 256, in __call__
    fn(*args, **kw)
  File "/home/mbrynski/.local/lib/python3.4/site-packages/SQLAlchemy-1.0.13-py3.4-linux-x86_64.egg/sqlalchemy/orm/events.py", line 614, in wrap
    fn(*arg, **kw)
  File "/home/mbrynski/caravel/caravel/models.py", line 292, in set_perm
    ds = db.session.query(src_class).filter_by(id=int(id_)).first()
UnboundLocalError: local variable 'src_class' referenced before assignment
@xrmx xrmx added the !deprecated-label:bug Deprecated label - Use #bug instead label Sep 20, 2016
@maver1ck
Copy link
Contributor Author

maver1ck commented Sep 20, 2016

I'll try to work on this today.
This will be my first contribution to Caravel so please be patient.

@maver1ck
Copy link
Contributor Author

It's not so easy for me.
I tried to do following:

--- a/caravel/models.py
+++ b/caravel/models.py
@@ -289,9 +289,13 @@ def set_perm(mapper, connection, target):  # noqa
     elif target.druid_datasource_id:
         src_class = DruidDatasource
         id_ = target.druid_datasource_id
+    else:
+        flasher("Can't remove {} datasource with active slices".format(target.datasource_name), "danger")
+        return
     ds = db.session.query(src_class).filter_by(id=int(id_)).first()
     target.perm = ds.perm

But result is that I'm getting as many warning as slice count :>

I'm looking deeper into SQL Alchemy ORM (this is trigger on cascade delete)

@xrmx
Copy link
Contributor

xrmx commented Sep 21, 2016

Please note that #1078 will change things quite a bit around this code. The correct fix i think would be to add a signal handler for the deletion of SqlaTable or DruidDatasource and block the deletion if there are slices. We are losing the FK so we cannot do that in sqlalchemy.

@maver1ck
Copy link
Contributor Author

OK.
As #1078 was merged I'm looking into the problem.

@stale
Copy link

stale bot commented Apr 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

@stale stale bot added the inactive Inactive for >= 30 days label Apr 11, 2019
@stale stale bot closed this as completed Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
!deprecated-label:bug Deprecated label - Use #bug instead inactive Inactive for >= 30 days
Projects
None yet
Development

No branches or pull requests

2 participants