<div dir="ltr"><div><div>I agree with everything you said.<br><br>The problem occurs when a worker receives a task to perform a publish, but it doesn't have the plugin installed. As a result the call to publisher.cast() returns the master model. The publish task then tries to call a method on the master model that does not exist. The user then sees an attribute not found exception in the logs. It would be better to raise a more useful exception in the cast() method itself when it is not able to cast to anything. <br><br></div>One suggestion was to add an optional call_counter keyword argument to cast(self, call_count=0). The argument would only be passed in to cast(call_count=call_count+1) when it is being recursively called. Then we could check if line 113 is reached with call_count==0 and raise an exception saying that the master model could not be cast to a detail model. <br><br></div>Thoughts?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 26, 2017 at 1:23 PM, Michael Hrivnak <span dir="ltr"><<a href="mailto:mhrivnak@redhat.com" target="_blank">mhrivnak@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Interesting question. It looks like in this implementation, even if you call cast() on a master model, the method itself will kind-of-recursively call cast() on detail models until it gets to the most detailed one, which will return itself. So every time cast() is called, eventually the most detailed model is expected to have its cast() method called and must return itself.<div><br></div><div>We could add a special case where the last one raises an exception, and the next-to-last one catches it, but I'm not sure that extra complication would be worth it. We'd be making the most common case "exceptional".</div><div><br></div><div>Having the call be idempotent is also potentially a perk, depending on how you look at it. Based on all that, plus the doc block confirming that the behavior is intentional, I don't see a problem with the current behavior.</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, May 26, 2017 at 11:41 AM, Dennis Kliban <span dir="ltr"><<a href="mailto:dkliban@redhat.com" target="_blank">dkliban@redhat.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Looking at the cast() method[0] it looks like it's possible to call cast() on a detail model. I would like to figure out when we expect to call cast() on a detail model. Without fully knowing the motivation for this implementation, I am inclined to raise an exception when the code reaches line 113. The exception would inform the developer that calling cast() is only appropriate on a master model. What are your thoughts?<br><br><br>[0] <a href="https://github.com/pulp/pulp/blob/3.0-dev/platform/pulp/app/models/base.py#L113" target="_blank">https://github.com/pulp/pulp/b<wbr>lob/3.0-dev/platform/pulp/app/<wbr>models/base.py#L113</a><span class="m_1916979690579757834HOEnZb"><font color="#888888"><br><br><br></font></span></div><span class="m_1916979690579757834HOEnZb"><font color="#888888">-Dennis<br></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
Pulp-dev mailing list<br>
<a href="mailto:Pulp-dev@redhat.com" target="_blank">Pulp-dev@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/pulp-dev" rel="noreferrer" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/pulp-dev</a><br>
<br></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div class="m_1916979690579757834gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><p style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px;margin:0px!important;padding:0px!important"><span style="margin:0px!important;padding:0px!important">Michael</span> <span style="margin:0px!important;padding:0px!important">Hrivnak</span></p><p style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px;margin:0px!important;padding:0px!important"></p><span style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px;margin:0px!important;padding:0px!important"><span style="margin:0px!important;padding:0px!important">Principal Software Engineer</span><span style="margin:0px!important;padding:0px!important">, <span style="margin:0px!important;padding:0px!important">RHCE</span></span> </span><span style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px"></span><br style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px;margin:0px!important;padding:0px!important"><p style="color:rgb(0,0,0);font-family:overpass-mono,monospace;font-size:10px;margin:0px!important;padding:0px!important">Red Hat</p></div></div>
</font></span></div>
</blockquote></div><br></div>