lukefitzwolfgang / icatproject

Automatically exported from code.google.com/p/icatproject
0 stars 0 forks source link

INCLUDE of one to many relation gets ignored if no corresponding objects are found #130

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Assume that an Investigation is defined at the ICAT server, but there are no 
Shifts related to this investigation.  Using a Python client, the following 
happens:

>>> searchstr = "Investigation INCLUDE Keyword, Shift [id=98]"
>>> inv = client.service.search(sessionId, searchstr)[0]
>>> inv.shifts
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: investigation instance has no attribute 'shifts'

That is, the list of Shifts is not included in the search result, although 
explicitly requested.

What is the expected output? What do you see instead?

Since there are no shifts related to this investigation, i'd expect an empty 
list in the search result.

Please use labels and text to provide additional information.

I checked it also on the level of SOAP messages.  This is the search result 
returned by the server (added line breaks and indentation for readability):

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:searchResponse xmlns:ns2="http://icatproject.org">
      <return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:type="ns2:investigation">
        <createId>useroffice</createId>
        <createTime>2013-12-20T09:04:59+01:00</createTime>
        <modTime>2013-12-20T09:04:59+01:00</modTime>
        <id>98</id>
        <modId>useroffice</modId>
        <keywords>
          <createId>useroffice</createId>
          <createTime>2013-12-20T09:04:59+01:00</createTime>
          <modTime>2013-12-20T09:04:59+01:00</modTime>
          <id>100</id>
          <modId>useroffice</modId>
          <name>Durol</name>
        </keywords>
        <name>2008-HIKE-0255-1</name>
        <startDate>2008-03-13T11:39:42+01:00</startDate>
        <title>Durol single crystal</title>
        <visitId>1</visitId>
      </return>
    </ns2:searchResponse>
  </S:Body>
</S:Envelope>

I'd expect something like "<shifts></shifts>" or "<shifts/>" in the return.

Original issue reported on code.google.com by rolf.kr...@helmholtz-berlin.de on 6 Jan 2014 at 11:49

GoogleCodeExporter commented 9 years ago
I think this is a feature of the Python API. The generated Java client has:

public List<Shift> getShifts() {
        if (shifts == null) {
            shifts = new ArrayList<Shift>();
        }
        return this.shifts;
    }

so Java users don't see the problem. I think this will require a fix on any 
Python code.

I think this will get changed to WontFix but people should be allowed to 
comment first.

Steve

Original comment by dr.s.m.f...@gmail.com on 6 Jan 2014 at 4:06

GoogleCodeExporter commented 9 years ago
That is exactly why I checked the issue on the level of the SOAP messages, to 
make sure that it is not due to client interference: shifts is not included in 
the server reply.

It may be that the Java client tries to works around this by inventing an empty 
list in the reply when there is none.  Whether this client behavior does more 
good or more harm is a separate question.

It makes a difference whether there are no shifts in the investigation object 
because the search request didn't ask to include them or whether the list of 
shifts is actually empty because none have been found at the server.

Original comment by rolf.kr...@helmholtz-berlin.de on 7 Jan 2014 at 7:36

GoogleCodeExporter commented 9 years ago
Python code will have to deal with this. It is not an ICAT issue as far as I 
can see. I will therefore mark it as invalid.

Original comment by dr.s.m.f...@gmail.com on 10 Mar 2014 at 12:52