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

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.

Related

How do i find mongodb collection and update multiple fields using pymongo

This is the code snippet
send = mongo.db.subscription
send.find().update({'$set':{'status': "expired"}})
this is the output i get
send.find().update({'$set':{'status': "expired"}})
AttributeError: 'Cursor' object has no attribute 'update'
The syntax you want is:
send.update_many({<filter_condition>}, {'$set':{'status': "expired"}})

Retrieve and Rank Python: What kind of "Answer Data" to pass to rank method?

I'm accessing the Retreive-And-Rank service using Python. So far I've uploaded my configuration and documents and have trained my ranker on the relevance file. All that is left, I presume, is to pass some query results (from Solr?) into the "rank" method of my R-A-R object.
My question: What exactly are those results, and what form do they come in? And how do I access them?
Right now I am accessing the PySolr object using the get_pysolr_client() method, then searching a query and using the returned results:
answer_data = pysolr.search(query)
rrv1.rank(<my_ranker_id>, answer_data, top_answers=10)
I'm doing this because it's analogous to what IBM does in the rank() method in the Java example. But I'm getting the error message:
AttributeError: 'Results' object has no attribute 'read'
I'm getting this because PySolr returns a "Results" object.
What should I be passing instead to the rank() method to get it to work?
The Retrieve_and_Rank specification for the rank method is as follows, and I think that answer_data is supposed to be a "file-like" object:
def rank(self, ranker_id, answer_data, top_answers=10)
One workaround is to call pysolr's _send_request method:
results = pysolr._send_request("GET", path="/fcselect?q=%s&ranker_id=%s&wt=json" %
(query_string, ranker_id))
for doc in json.loads(results)["response"]["docs"]:
print doc
Thanks to rishavc on dW Answers for this.

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

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))

How do I update the status of an asset in VersionOne using the REST API

How can I update the status of an asset in V1 using the Rest API?
I would assume I could do something like this using the Python SDK:
from v1pysdk import V1Meta
v1 = V1Meta()
for s in (v1.PrimaryWorkitem
.filter("Number='D-01240'")):
s.StoryStatus = v1.StoryStatus(134)
v1.commit()
This is at least how I understand the Python SDK examples here:
https://github.com/versionone/VersionOne.SDK.Python
However this does not change anything, even though I have the rights to change the status.
Try using:
s.Status = v1.StoryStatus(134)
According to ~/meta.v1?xsl=api.xsl#PrimaryWorkitem The attribute on PrimaryWorkitem of type StoryStatus is named Status, so I think it's just a mistaken attribute name.
What's probably happening is that you're setting a new attribute on that python object, but since StoryStatus is not one of the setters that the SDK created from the instance schema metadata, it doesn't attempt to add it to the uncommitted data collection, and thus the commit is a no-op and yields neither error nor any action.
It might be possible to fence off arbitrary attribute access on those objects so that misspelled names raise errors. I'll investigate adding that.
Try doing:
s.set(Status = v1.StoryStatus(134))

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