AttributeError: 'PullRequest' object has no attribute 'issue_comments' - python

I'm using https://github.com/sigmavirus24/github3.py
and I'm having problem with getting issue_comments from PR.
for pr in repo.iter_pulls():
for comment in pr.issue_comments():
print comment
I'm getting
AttributeError: 'PullRequest' object has no attribute
'issue_comments'
What I'm doing wrong here? review_comments for example is working just fine

The review_comments method was added very recently and was backported from the next planned version of github3.py (1.0). When it was backported, to reduce migration headaches from 0.9.x to 1.0, we decided to not prefix it with iter_ like the other similar methods. In short, the method you are looking for is: iter_issue_comments.
The following should work
TEMPLATE = """{0.user} commented on #{0.number} at {0.created_at} saying:
{0.body}
"""
for pr in repo.iter_pulls()
for comment in pr.iter_issue_comments():
print(TEMPLATE.format(comment))

Related

pymongo Collection initialize_unordered_bulk_op method broken

TypeError("'Collection' object is not callable. If you meant to call the 'initialize_unordered_bulk_op' method on a 'Collection' object it is failing because no such method exists.")
Anyone else run into this?
Ran into this problem in pymongo v4.0. Release notes mention this, but it wasn't very obvious.
Changed in version 4.0: Removed the reindex, map_reduce, inline_map_reduce, parallel_scan, initialize_unordered_bulk_op, initialize_ordered_bulk_op, group, count, insert, save, update, remove, find_and_modify, and ensure_index methods.
Refer to Migration Guide

AttributeError: 'CollectionReference' object has no attribute 'orderBy'

I'm trying to order a firestore collection by the field name, but it's giving me this error: AttributeError: 'CollectionReference' object has no attribute 'orderBy'.
My code:
participants_ref = db.collection("participants")
docs = participants_ref.orderBy("name").stream()
In case this helps, I've also printed out participants_ref and I get the following:
<google.cloud.firestore_v1.collection.CollectionReference object at 0x0000021C9EAB7F40>
According to the documentation, the method you're looking for is order_by. Be sure to switch the code language tab to "Python" to see the correct usage.
docs = participants_ref.order_by("name").stream()
Also see the python API documentation for CollectionReference.

Appending to relationship

Given a simple one to many relationship where one page can be linked to multiple errors:
class Page(Base):
...
errors = relationship('Error', back_populates='page')
class Error(Base):
...
page = relationship('Page', back_populates='errors')
I add error objects to a page object simple by
page.errors.append(error)
This works. However PyCharm warns about Error would have no reference "append".
My Question: Is this just PyCharm not understanding that Page.errors is of type list(?) and not Error or is is there something I should do better?
If someone stumbles upon the same problem: I did not notify any problems yet and so I guess it is simply pycharm not recognising the type correctly. You can simple help it by using type hints:
class Page(Base):
...
errors: list = relationship('Error', back_populates='page')

Pylons and WebHelpers: url() method

Following Pylons sample code regarding the "helpers", there's the following snippet:
${h.form(h.url(action='email'), method='get')}
Email Address: ${h.text('email')}
${h.submit('Submit')}
${h.end_form()}
However, apparently, there's no url method in WebHelpers as the server throws AttributeError: 'module' object has no attribute 'url'.
Am I doing something wrong? If no, what is the equivalent of url()?
Somehow obscure for someone new to Pylons. It should have been mentioned in the docs, IMHO.
The answer to "Mocking away the url object in Pylons", has my answer. I need from pylons import url in helpers.py.

python cherrypy session usage example of cherrypy.lib.sessions

I am total newbie with cherrypy.
My setup: Arch Linux, Python 3.3, tornado, cherrypy 3.2
Trying to implement session handling for a web app using cherrypy.lib.sessions (for some reason often referred to as cherrypy.sessions in various forums, might be another version)
I am looking for an example of the following:
instantiate a session object
set a value of an arbitrarily named attribute
write session into a session file
read session info from session file
access the the value of the modified attribute
My (relevant) code:
import cherrypy
class RequestHandlerSubmittedRequest(tornado.web.RequestHandler):
def get(self):
SetState(self)
def SetState(self):
cherrypy.config.update({'tools.sessions.on': True})
cherrypy.config.update({'tools.sessions.storage_type': 'file'})
#directory does exist
cherrypy.config.update({'tools.sessions.storage_path': '/tmp/cherrypy_sessions'})
cherrypy.config.update({'tools.sessions.timeout': 60})
cherrypy.config.update({'tools.sessions.name': 'hhh'})
So far so good. Now:
obj_session = cherrypy.lib.sessions.FileSession
Here I get the first snag (or misunderstanding).
The returned obj_session contains no session ID of any kind, just an empty object frame. Also: no file is created at this point in /tmp/cherrypy_sessions -
should not it be there now? I would expect it to be created and named after its session ID.
OK, no ID in the object, let's assign one:
session_id = obj_session.generate_id(self)
This returns a long random string as it should I guess
And now I don't know how to proceed with assignments and saving calling obj_session.save() or obj_session.load() with several variations of input gives "AttributeError: 'module' object has no attribute X" where X can be "load" and couple of other keywords. Passing self or obj_session itself to the methods does not help, just changes the wording of the error. I must be going in a very wrong direction in general.
So, is there an example of those five steps above? I could not find one anywhere.
Thanks.
Igor

Categories