<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:57:24 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-1572] If there are no matches, findandmodify() should return an empty result, not raise an exception.</title>
                <link>https://jira.mongodb.org/browse/SERVER-1572</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;See comments on (closed) &lt;a href=&quot;https://jira.mongodb.org/browse/PYTHON-152&quot; title=&quot;findandmodify raises pymongo.errors.OperationFailure when there are no matches&quot; class=&quot;issue-link&quot; data-issue-key=&quot;PYTHON-152&quot;&gt;&lt;del&gt;PYTHON-152&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; findandmodify() raises pymongo.errors.OperationFailure when there are no matches:&lt;/p&gt;

&lt;p&gt;  File &quot;build/bdist.linux-x86_64/egg/pymongo/database.py&quot;, line 294, in command &lt;br/&gt;
 pymongo.errors.OperationFailure: command SON([(&apos;findandmodify&apos;, &apos;my_queue&apos;), (&apos;sort&apos;, &lt;/p&gt;
{&apos;_id&apos;: -1}
&lt;p&gt;), (&apos;query&apos;, {&apos;started&apos;: {&apos;$exists&apos;: False}}), (&apos;update&apos;, {&apos;$set&apos;: {&apos;started&apos;: 1280965374}})]) failed: No matching object found &lt;/p&gt;


&lt;p&gt;According to the mongodb documentation for findandmodify:&lt;/p&gt;

&lt;p&gt;&quot;This command can be used to atomically modify a document (at most one) and return it.&quot;&lt;/p&gt;

&lt;p&gt;This implies that findandmodify() behaves much like the find() command--it is perfectly acceptable to not have a match at all.&lt;br/&gt;
Such behavior makes perfect sense. I do not believe it should constitute a command failure simply because there are no matches.&lt;br/&gt;
No matches should return an empty result, not raise a command failure exception.&lt;/p&gt;

&lt;p&gt;IMO, command failure, should be when it finds a match but fails to make the modification, or some other actual but unexpected condition occurs.&lt;/p&gt;

&lt;p&gt;This is a very common use case--a consumer pulling things off a queue. When the queue is empty, it shouldn&apos;t be generating an exception, just returning empty. It yields much nicer code.&lt;/p&gt;
</description>
                <environment>Ubuntu 10.4, x86-64</environment>
        <key id="12676">SERVER-1572</key>
            <summary>If there are no matches, findandmodify() should return an empty result, not raise an exception.</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="2">Won&apos;t Fix</resolution>
                                        <assignee username="mathias@mongodb.com">Mathias Stearn</assignee>
                                    <reporter username="nick@leippe.com">Nick Leippe</reporter>
                        <labels>
                    </labels>
                <created>Thu, 5 Aug 2010 15:48:35 +0000</created>
                <updated>Mon, 19 May 2014 22:09:34 +0000</updated>
                            <resolved>Mon, 25 Oct 2010 22:32:27 +0000</resolved>
                                    <version>1.5.6</version>
                                                                        <votes>3</votes>
                                    <watches>5</watches>
                                                                                                                <comments>
                            <comment id="19626" author="redbeard0531" created="Mon, 25 Oct 2010 22:32:27 +0000"  >&lt;p&gt;I think the server behavior is correct since find_and_modify on a non-existent object with upsert=false is usually an error and at the very least should be handled differently from normal behavior since no modification has taken place.&lt;/p&gt;

&lt;p&gt;I helped your issue by adding a helper in python that matches the shell&apos;s behavior. That is, returning null/None in that case and {} as the original object when inserting on an upsert.&lt;/p&gt;</comment>
                            <comment id="19529" author="redbeard0531" created="Fri, 22 Oct 2010 21:10:13 +0000"  >&lt;p&gt;I think I will just add a find_and_modify helper to collections in pymongo. That should take care of this.&lt;/p&gt;</comment>
                            <comment id="16517" author="nick@leippe.com" created="Thu, 5 Aug 2010 17:51:08 +0000"  >&lt;p&gt;My last comment turns out is only half correct.&lt;/p&gt;

&lt;p&gt;The BaseException still has an args attribute that can be analyzed to implement the work around.&lt;br/&gt;
But, to do so requires: test the length (since it&apos;s optional), test the type (make sure it&apos;s a string or unicode type), then finally check the contents. A lot of work for a common, usual case.&lt;/p&gt;

&lt;p&gt;So, imo, the two solutions are:&lt;br/&gt;
1) return empty&lt;br/&gt;
2) create a specific exception for this case&lt;/p&gt;

&lt;p&gt;Creating a specific exception for a single case screams that it shouldn&apos;t be an exception. Hitting eof on a fd doesn&apos;t raise--you expect to hit it eventually, just like in this case, you expect to exhaust a queue at some point.&lt;/p&gt;</comment>
                            <comment id="16514" author="nick@leippe.com" created="Thu, 5 Aug 2010 17:14:36 +0000"  >&lt;p&gt;In attempting to work around this, I&apos;ve discovered that this behavior is even more critical to fix.&lt;br/&gt;
Here&apos;s why:&lt;/p&gt;

&lt;p&gt;It raises pymongo.errors.OperationFailure, which is derived from BaseException. There are possibly many reasons why this command could legitimately fail and would need to raise this exception. Therefore, in order to ascertain that it is the legitimate reason of not finding a match, the exception needs to be examined.&lt;/p&gt;

&lt;p&gt;The only data in the exception is the message attribute string which can be tested for the presence of the suffix &quot;failed: No matching object found&quot;. Good and dandy right?&lt;/p&gt;

&lt;p&gt;Except that when doing so yields:&lt;/p&gt;

&lt;p&gt;DeprecationWarning: BaseException.message has been deprecated as of Python 2.6&lt;/p&gt;

&lt;p&gt;Thus, when that attribute is gone, there will be no means of distinguishing this reason for this exception being raised from any other. This work-around will be broken as soon as the BaseException.message attribute is removed. (3.0? I couldn&apos;t find anywhere saying when that will be done.)&lt;/p&gt;
</comment>
                            <comment id="16511" author="nick@leippe.com" created="Thu, 5 Aug 2010 16:29:15 +0000"  >&lt;p&gt;If there&apos;s concern about breaking existing code via a change in behavior, I suggest adding a new, optional parameter, which defaults to the existing behavior such as &quot;required&quot; or &quot;must_exist&quot;, or something along those lines.&lt;/p&gt;
</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="13472">PYTHON-170</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 22 Oct 2010 21:10:13 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 17 weeks, 2 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>false</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ian@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 17 weeks, 2 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>mathias@mongodb.com</customfieldvalue>
            <customfieldvalue>nick@leippe.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrphvr:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hriiev:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21635</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hszuef:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>