https://pulp.plan.io/https://pulp.plan.io/favicon.ico2015-12-18T16:07:06ZPulpRPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=74982015-12-18T16:07:06Zmhrivnakmhrivnak@redhat.com
<ul><li><strong>Triaged</strong> changed from <i>No</i> to <i>Yes</i></li></ul> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=75492015-12-22T16:48:34Zbmbouterbmbouter@redhat.com
<ul><li><strong>Status</strong> changed from <i>NEW</i> to <i>ASSIGNED</i></li><li><strong>Assignee</strong> set to <i>bmbouter</i></li></ul> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=76272016-01-04T20:37:38Zbmbouterbmbouter@redhat.com
<ul></ul><p>I've determined this is safe. I'm making a PR removing the scary TODO, but I'm writing what I've learned here.</p>
<p>mongoengine.Document provides <code>__eq__()</code> and <code>__neq__()</code>. It does not provide other rich comparison methods (ie: <code>__lt__()</code>, <code>__ge__()</code>, ...). It also does not provide <code>__cmp__()</code>. Python Data Model docs state that since Python 2.1 "[<code>__cmp__()</code> is called] by comparison operations if rich comparison (see above) is not defined." [0] This behavior ensures that for == and != operations which mongoengine expects to have its <code>Document.__eq__()</code> and <code>Document.__neq__()</code> will be used as expected.</p>
<p>Also since mongoengine doesn't provide rich comparison operators we can be reasonably sure that it's not relying on the mostly non-sense comparison provided by the built in object.__lt__ implementation and other default rich comparison operators. Since mongoengine couldn't make meaningful use of these defaults, Pulp is free to define the comparison with <code>__cmp__()</code> as necessary.</p>
<p>One area of concern comes from the mongoengine's <code>__eq__()</code> and <code>__neq__()</code> being called instead of the <code>__cmp__()</code> when Pulp is comparing the equality or inequality of two units. The <code>__eq__()</code> and <code>__neq__()</code> of mongoengine is an ObjectId comparison of the _id fields. The <code>__cmp__()</code> Pulp has historically used would be a tuple comparison of (epoch, version, release) which could cause things that were considered equal to no longer being equal. In this area I think we should just bugfix as problems come up. If two units are not the same record in the DB, the equality comparison of them should not say they are so this new behavior is more correct.</p>
<p>Note that for Python 3 compatibility we will need to replace <code>__cmp__()</code> usage with the <code>__lt__()</code>, <code>__le__()</code>, <code>__gt__()</code>, <code>__ge__()</code>. When we do that we should <strong>not</strong> implement <code>__eq__()</code> or <code>__neq__()</code> because we could be affecting mongoengine internal behaviors by doing so.</p>
<p>For fun, here [1] is an interesting example of the motivation for rich operators which uses RPM tracking as the example.</p>
<p>[0]: <a href="https://docs.python.org/2/reference/datamodel.html#object.__cmp" class="external">https://docs.python.org/2/reference/datamodel.html#object.__cmp</a>__<br>
[1]: <a href="http://www.gerg.ca/blog/post/2012/python-comparison/" class="external">http://www.gerg.ca/blog/post/2012/python-comparison/</a></p> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=76282016-01-04T20:43:05Zbmbouterbmbouter@redhat.com
<ul><li><strong>Status</strong> changed from <i>ASSIGNED</i> to <i>POST</i></li></ul><p>PR available at: <a href="https://github.com/pulp/pulp_rpm/pull/758" class="external">https://github.com/pulp/pulp_rpm/pull/758</a></p> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=76322016-01-05T13:59:09Zbmbouterbmbouter@redhat.com
<ul><li><strong>Status</strong> changed from <i>POST</i> to <i>MODIFIED</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>Applied in changeset <a class="changeset" title="Removes scary TODO about __cmp__ usage on NonMetadataPackage closes #1435 https://pulp.plan.io/i..." href="https://pulp.plan.io/projects/pulp_rpm/repository/9/revisions/bbaddd8f7c0b65914c2c01327f4b5f9370228fcf">bbaddd8f7c0b65914c2c01327f4b5f9370228fcf</a>.</p> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=88862016-02-11T21:25:56Zrbarlow
<ul><li><strong>Status</strong> changed from <i>MODIFIED</i> to <i>5</i></li></ul> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=99992016-03-23T18:13:17Zdkliban@redhat.com
<ul><li><strong>Status</strong> changed from <i>5</i> to <i>CLOSED - CURRENTRELEASE</i></li></ul> RPM Support - Issue #1435: Determine if __cmp__ in Package model is safe with mongoenginehttps://pulp.plan.io/issues/1435?journal_id=393942019-04-15T20:40:05Zbmbouterbmbouter@redhat.com
<ul><li><strong>Tags</strong> <i>Pulp 2</i> added</li></ul>