ome / omero-py

Python project containing Ice remoting code for OMERO
https://www.openmicroscopy.org/omero
GNU General Public License v2.0
20 stars 33 forks source link

suConn fails with `_BlitzGateway object has no attribute '_ctx'` #289

Open glyg opened 3 years ago

glyg commented 3 years ago

Hi ome team,

I have an error when trying to use suConn

...
File "/opt/omero/server/impomero-main/impomero/annotation_job.py", line 60, in auto_annotate
user_conn = conn.suConn(user)
File "/opt/omero/server/venv3/lib64/python3.6/site-packages/omero/gateway/__init__.py", line 1853, in suConn
if self.isAdmin():
File "/opt/omero/server/venv3/lib64/python3.6/site-packages/omero/gateway/__init__.py", line 2435, in isAdmin
return self.getEventContext().isAdmin
File "/opt/omero/server/venv3/lib64/python3.6/site-packages/omero/gateway/__init__.py", line 2322, in getEventContext
if self._ctx is None:
AttributeError: '_BlitzGateway' object has no attribute '_ctx'

This occurs if the BlitzGateway was not connected before suConn is called, as the _ctx attribute is not created. Maybe a more explicit connection error could be raised in this case?

glyg commented 3 years ago

of course I'm happy to open a PR for that if needed.

will-moore commented 3 years ago

Thanks for reporting. It would certainly be nicer to have an explicit connection error here. But I realise that the same is true of almost all the methods on the BlitzGateway - You'll get some error if you try to call them before you're connected, but it's not handled uniformly anywhere.

I guess we could create an @assert_connected decorator for all the methods we want to handle this, but that's probably a bigger job than you're looking for!?

glyg commented 3 years ago

I guess we could create an @assert_connected decorator for all the methods we want to handle this, but that's probably a bigger job than you're looking for!?

:smile: I can surely write the decorator, and apply it to getEventContext, but I would let you judge where else to apply it!