pyax fails to return results when COUNT() is used in SOQL

Bug #301187 reported by Ray C Horn
2
Affects Status Importance Assigned to Milestone
pyax
Fix Committed
High
Kevin Shuk

Bug Description

Consider the following SOQL statement:

Select COUNT() from Solution s WHERE (s.Status = 'Published') AND (s.IsDeleted = False) AND (s.LastModifiedDate > 2008-08-24T00:00:00.000Z)

The results pyax reports from connection.py in the __processQueryResult method is an empty {} in the query_result_batch variable.

The problem is the query_result says {u'records': None, u'done': True, u'queryLocator': None, u'size': '106'}.

The fix would be to add the following exception code as follows:

        query_result_batch = self.__resultToObject(sobject_records)
        if (done is True) and (len(query_result_batch) == 0):
            query_result_batch = query_result
        return query_result_batch

This is a hack but it works so long as I get something back from the SOQL rather than nothing which is what pyax wants to give me.

Perhaps the development team can give me a more elegant solution in a later release however since I need this to work now I am using my own hack in the meantime.

I suspect the pyax development team simply did not expect people to use the COUNT() function which can be useful even though it does not return any SalesForce objects it does return the number of items a SOQL would return.

Revision history for this message
Ray C Horn (mrpython94596) wrote :

Refined the fix for this bug a bit:

        query_result_batch = self.__resultToObject(sobject_records)
        if (done is True) and (len(query_result_batch) == 0):
            query_result_batch = query_result if (str(query_result.__class__).find('pyax.xmltramp.Element') == -1) else []
        return query_result_batch

Let's just say this works for me...

Revision history for this message
Ray C Horn (mrpython94596) wrote :

yet another refinement now that I am using 0.9.7 and my previous fix for this issue seems to be moot...

    def __processQueryResult(self, query_result):
        """ processes the result from a query or queryAll call into an
        Batch, calling queryMore as necessary to complete the query
        operation

        @param query_result: return result from a query or queryAll call
        @note: Although queryMore also returns a query_result this is not
            intended to be a primary input to this method. Rather, these are
            handled internally to this method and aggregated into the
            query_result_batch

        @return: a Batch populated with the sobject(s) found by the
            query call that produced the query_result parameter.
        @rtype: pyax.sobject.batch.Batch
        """
        sobject_records, done, query_locator = self._unpackQueryResult(query_result)
        sobject_records = sobject_records if (isinstance(sobject_records,list)) else [sobject_records]
        while not done:
            records, done, query_locator = self._unpackQueryResult(query_result)
            sobject_records.extend(records)

        query_result_batch = self.__resultToObject(sobject_records)
        if (done is True) and (len(query_result_batch) == 0):
            query_result_batch = dict([(k,query_result[k]._dir) for k in query_result.keys()])
        return query_result_batch

This fix seeks to return the COUNT() as a dict.

This is just my 2 cents since the original pyax code did not even handle the COUNT() SOQL Statement at-all but if it did handle COUNT() it was not clear to me from the code I saw from pyax.

Revision history for this message
Kevin Shuk (surf) wrote :

I will have to check the query itself to to see if it's a select count() and act accordingly, otherwise a legitimate query that returns no rows may provide a surprising result (not an empty batch).

Borrowing behaviour from apex, the count() query should return just the integer. It's a different enough kind of query to warrant this, and since SOQL isn't SQL, I don't feel quite so bad about the different behaviour.

Changed in pyax:
assignee: nobody → surf
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Kevin Shuk (surf) wrote :

Committed to rev 65

Changed in pyax:
status: Confirmed → Fix Committed
Revision history for this message
Ray C Horn (mrpython94596) wrote : Re: [Bug 301187] Re: pyax fails to return results when COUNT() is used inSOQL

My own bug fix remains where it is - my version of pyax always behaves the
same across the board regardless of the SOQL.

--------------------------------------------------
From: "Kevin Shuk" <email address hidden>
Sent: Friday, January 23, 2009 4:31 PM
To: <email address hidden>
Subject: [Bug 301187] Re: pyax fails to return results when COUNT() is used
inSOQL

> I will have to check the query itself to to see if it's a select count()
> and act accordingly, otherwise a legitimate query that returns no rows
> may provide a surprising result (not an empty batch).
>
> Borrowing behaviour from apex, the count() query should return just the
> integer. It's a different enough kind of query to warrant this, and
> since SOQL isn't SQL, I don't feel quite so bad about the different
> behaviour.
>
> ** Changed in: pyax
> Importance: Undecided => High
> Assignee: (unassigned) => Kevin Shuk (surf)
> Status: New => Confirmed
>
> --
> pyax fails to return results when COUNT() is used in SOQL
> https://bugs.launchpad.net/bugs/301187
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Salesforce.com Apex API library for Python: Fix Committed
>
> Bug description:
> Consider the following SOQL statement:
>
> Select COUNT() from Solution s WHERE (s.Status = 'Published') AND
> (s.IsDeleted = False) AND (s.LastModifiedDate > 2008-08-24T00:00:00.000Z)
>
> The results pyax reports from connection.py in the __processQueryResult
> method is an empty {} in the query_result_batch variable.
>
> The problem is the query_result says {u'records': None, u'done': True,
> u'queryLocator': None, u'size': '106'}.
>
> The fix would be to add the following exception code as follows:
>
> query_result_batch = self.__resultToObject(sobject_records)
> if (done is True) and (len(query_result_batch) == 0):
> query_result_batch = query_result
> return query_result_batch
>
> This is a hack but it works so long as I get something back from the SOQL
> rather than nothing which is what pyax wants to give me.
>
> Perhaps the development team can give me a more elegant solution in a
> later release however since I need this to work now I am using my own hack
> in the meantime.
>
> I suspect the pyax development team simply did not expect people to use
> the COUNT() function which can be useful even though it does not return
> any SalesForce objects it does return the number of items a SOQL would
> return.
>

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.