[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-bugzilla
Subject:    =?utf-8?q?=5Bpython-bugzilla=5D?= Re: script stopped working after upgrading to 2.0.0
From:       Cole Robinson <crobinso () redhat ! com>
Date:       2017-02-17 1:27:45
Message-ID: 719af1cf-e574-77a3-d6fd-9e33567ae40a () redhat ! com
[Download RAW message or body]

On 02/16/2017 08:00 PM, Dennis Kliban wrote:
> On Thu, Feb 16, 2017 at 7:15 PM, Cole Robinson <crobinso@redhat.com
> <mailto:crobinso@redhat.com>> wrote:
> 
>     On 02/16/2017 01:44 PM, Dennis Kliban wrote:
>     > I have some code that looks very similar to what I have below.
>     >
>     >
>     > from bugzilla.rhbugzilla import RHBugzilla
>     >
>     > BUGZILLA_URL = 'https://bugzilla.redhat.com'
>     > BZ = RHBugzilla(url='%s/xmlrpc.cgi' % BUGZILLA_URL, user=user, password=password)
>     > bugzilla_bugs = BZ.query(RHBugzilla.url_to_query(non_closed_bug_with_ext_tracker))
>     >
>     > for bug in bugzilla_bugs:
>     >     for external_bug in bug.external_bugs:
>     >         print external_bug
>     >
>     >
>     > This works fine with python-bugzilla 1.2.2, but when switching to 2.0.0, I get
>     > an exception like this:
>     >
>     >
>     > Traceback (most recent call last):
>     >   File "pulp_packaging/ci/redmine_bugzilla.py", line 242, in <module>
>     >     main()
>     >   File "pulp_packaging/ci/redmine_bugzilla.py", line 193, in main
>     >     for external_bug in bug.external_bugs:
>     >   File "/usr/lib/python2.7/site-packages/bugzilla/bug.py", line 110, in
>     > __getattr__
>     >     raise AttributeError(msg)
>     > AttributeError: Bug object has no attribute 'external_bugs'.
>     >
>     >
>     > Does anyone have a suggestion for how to fix my script?
> 
>     Hmm, not sure, can you send me the specific query you are using and a link to
>     the code? Off list if you prefer
> 
> 
> The actual script and query are here:
> https://github.com/pulp/pulp_packaging/blob/master/ci/redmine_bugzilla.py#L111
> 

Okay, this is a roundabout issue due to the semantic change I mentioned at the
top here, about bug_autorefresh:

http://blog.wikichoon.com/2016/06/python-bugzilla-api-changes-in-git.html

Your script was implicitly depending on python-bugzilla's 'auto refresh'
behavior, where if you tried to access a bug field that wasn't pulled down
with the initial XMLRPC query, we would go out and try to fetch it from
bugzilla for you. However this pattern encouraged poorly performing code that
hammered bugzilla far to much.

The ideal fix in this case is to edit the code to do this:

query = BZ.url_to_query(non_closed_bug_with_ext_tracker)
query["extra_fields"] = ["external_bugs"]
bugzilla_bugs = BZ.query(query)

What this says is 'ask bugzilla to return the extra_field named external_bugs
with the query results'. One major benefit is that you'll notice the code is
now way faster, since it's only fetching the bug data with a single XMLRPC
call, where previously it would perform an implicit XMLRPC call on the first
bug.external_bugs access for each bug. (this is why I changed the behavior)

If you're curious, the requirement to specify extra_fields for external_bugs
is just how the bugzilla XMLRPC API works in this case, for certain fields
(data heavy ones like comments/attachments, and non-standard ones like
external_bugs) the API requires you to manually request that data, rather than
returning it by default.

Hopefully that explains things, let me know if you hit any more issues

Thanks,
Cole
_______________________________________________
python-bugzilla mailing list -- python-bugzilla@lists.fedorahosted.org
To unsubscribe send an email to python-bugzilla-leave@lists.fedorahosted.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic