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

Session ID and constructor #400

Merged
merged 18 commits into from
Apr 24, 2024
Merged
18 changes: 16 additions & 2 deletions src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,14 +1525,24 @@ def __init__(self, username=None, passwd=None, client_obj=None, group=None,
self.ice_config = [os.path.abspath(str(x)) for x in [_f for _f in self.ice_config if _f]]

self.host = host
if self.c is not None:
self.host = self.c.getProperty("omero.host")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could imagine an scenario where a user tries to connect to a server with the wrong client object, which would then cause some ambiguity over exactly which server Blitz is connected to.

Could I suggest that we check if self.host is already set to something different here, and if there's a mismatch throw an error?

Copy link
Member Author

@jburel jburel Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a check but i think people either specify the "client" or the host/user/password
Checking the host does not stop the connection to a wrong server. Using the "connect" specifying the sessionID could lead to that situation cf. one of the examples in the description and there is "false" value return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the gateway is too "flexible" leading to some very strange situations.

Copy link
Member Author

@jburel jburel Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also set the identity if a client with connection is specified?
the same will apply i.e. checking the value from client and via constructor.

Client with session specified, specify user name and password different from the client ones. Identity in gateway does not correspond to the identity in client

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that people should either specify client or host, but in the event that they don't I think it's safer to avoid silently overriding the user-supplied host parameter. Some of the autocompletion tools people now use do have a habit of trying to fill every argument. The user really should be reading the docs, but at the same time I don't think Gateway's Python docs are as helpful as they need to be.

You're probably right that Gateway's excessive flexibility here may be causing more problems than it solves. An alternative might be to validate the connection in the client object and outright reject calls with the other parameters specified - you either init with a connected client or supply credentials, no "mix and match".

Copy link
Member Author

@jburel jburel Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other problems especially with the connect method since new clients get created (even if one was specified in the constructor).
So probably need to describe what we expect from each method moving forward

Copy link
Member Author

@jburel jburel Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I look into it the more I notice points that require clarification.
The clone method for example will not work when a client with session is specified.
To make it works one should do

BlitzGateway(client_obj=client)
conn.setIdentity(user, password)

We also lose info like useragent and userid in that case

self.port = port
if self.c is not None:
self.port = self.c.getProperty("omero.port")
self.secure = secure
self.useragent = useragent
self.userip = userip

self._sessionUuid = None
self._session_cb = None
self._session = None
if self.c is not None:
try:
self._sessionUuid = self.c.getSessionId()
self._session = self.c.getSession()
except omero.ClientError: # no session available
pass
self._lastGroupId = None
self._anonymous = anonymous
self._defaultOmeroGroup = None
Expand Down Expand Up @@ -2082,8 +2092,12 @@ def _resetOmeroClient(self):
logger.debug(self.ice_config)

if self.c is not None:
self.c.__del__()
self.c = None
try:
if self.c.getSessionId() != self._sessionUuid:
jburel marked this conversation as resolved.
Show resolved Hide resolved
self.c.__del__()
self.c = None
except omero.ClientError: # no session available
pass

if self.host is not None:
if self.port is not None:
Expand Down
Loading