ome / omero-marshal

OMERO marshalling infrastructure
https://pypi.org/project/omero-marshal/
GNU General Public License v2.0
3 stars 11 forks source link

Handle shape None and Masks #40

Open will-moore opened 7 years ago

will-moore commented 7 years ago

As I've found myself and reported by @waxenegger, if you have a DB where shapes are None or Masks, then self.ctx.get_encoder(shape.__class__) returns None and you get an exception.

https://github.com/openmicroscopy/openmicroscopy/pull/5231#issuecomment-291777836

We can ignore this by simply checking whether we have an encoder:

            for shape in obj.copyShapes():
                shape_encoder = self.ctx.get_encoder(shape.__class__)
                if shape_encoder is not None:
                    shapes.append(shape_encoder.encode(shape))

but I wonder if we want to indicate that some Shapes in the sequence are None / Masks, with an appropriate placeholder?

In webgateway/views.py get_rois_json() which is used for current viewer ROIs/Shapes, we have a None check for shapes:

        for s in r.copyShapes():
            if s is None:   # seems possible in some situations
                continue
            shapes.append(shapeMarshal(s))
sbesson commented 7 years ago

Thanks @will-moore @waxenegger and definitely :+1: for handling these exceptions instead of throwing. Two comments:

waxenegger commented 7 years ago

@sbesson Personally I haven't experienced the None Shape szenario, I only encountered the Mask situation.

Looking at the db I can see how a roi table entry might have no shape (empty/deleted shapes) but any row in the shape table has to have a roi id (NOT NULL). I mean there are plenty of columns that could be NULL. If anything I could only imagine that some query semantics turns a row into a NULL based on some other factor/NULL perhaps. But that's mere speculation, haven't done any code research to that end.

joshmoore commented 7 years ago

is it possible for a Shape to be None in the DB ? I thought this would not be allowed when inserting the entry

In OMERO if someone inserts a null in the ordered roi.shapes list then it is possible (if very unlikely) to get a null.