should I use .rank or .order_id? - python

accessing order_id property of a ScoredDocument object in SearchResults object generates following error in log:
DeprecationWarning: order_id is deprecated; use rank instead
logging.debug(document.order_id)
However documentation here refers to order_id: https://developers.google.com/appengine/docs/python/search/scoreddocumentclass
Which is correct? I am using SDK 1.7.3.

Documentation updates slower then the code, you should flow whatever the latest code recommends you to do.

You should use rank. I've filed a bug to fix that documentation. (I work on the Search API)

In the SdkReleaseNotes of the version 1.6.6 - May22, 2012 it writes:
"The Search API has deprecated the order_id attribute on Document class. It has been replaced with the rank attribute."
So obviously you should use rank.

Related

How to return and see all a Gitlab's Project Issue info using python-gitlab?

I am using python-gitlab to access my Gitlab repo's data and get a list of all my repo's issues by running the following:
project = gl.projects.get(#my_project_id)
issues = project.issues.list()
I can then print this list to see which issues are in the list.
issues
[<ProjectIssue iid:1>,<ProjectIssue iid:2>...]
I have also tried to get the info for a specific issue by running:
issue = project.issues.get(1) #example for issue 1
However, I don't know how to access all the info within that particular issue
When trying to run the "issue" line, I get the following, but I cannot see all the attributes and information of that issue. I'm looking for all the information that should be sent in the API response as defined here (eg. state, author, description, etc). How can I see this information?
issue
<ProjectIssue iid:1>
I know that python-gitlab has defined some methods like the .time_stats() to list the time stats for my issue, but I can't find which method to use to find ALL the information for that issue
[In] issue.time_stats()
[Out] {'time_estimate': 0, 'total_time_spent': 0, 'human_time_estimate': None, 'human_total_time_spent': None}
When you run project.issues.get(1) it's returning the GitLab Issue as an object (the ProjectIssue class), not as json or an array. I'm not familiar with python-gitlab (and haven't used python in years) but the issue data is likely accessible as an attribute:
issue = project.issues.get(1)
description = issue.description
labels = issue.labels
Note that some of the attributes of the ProjectIssue class might be another object.
To get all attributes on the ProjectIssue class, you can do
issue = project.issues.get(1)
getmembers(issue)
See this answer for more details.

mongoengine save method is deprecated?

I wonder why my python says that mongoengine save() method is deprecated? I don't see any info about this into official documentation https://mongoengine.readthedocs.io/en/v0.9.0/apireference.html
class MyModel(Document):
user_id = StringField(required=True)
date = DateTimeField(required=True, default=datetime.datetime.now)
my = MyModel()
my.user_id = 'user'
my.save()
and now i see:
/Library/Python/2.7/site-packages/mongoengine/document.py:340:
DeprecationWarning: save is deprecated. Use insert_one or replace_one
instead
I've python 2.7 and also installed pymongo, mongoengine and bottle-mongo (maybe some issues with that?)
MongoEngine wraps PyMongo, which deprecated "save" in PyMongo 3.0:
http://api.mongodb.com/python/current/changelog.html#collection-changes
MongoEngine might need to deprecate its save method, or suppress the deprecation warning, or perhaps some other fix to handle this PyMongo change. I recommend you search MongoEngine's bug tracker and report this issue if it has not been already.
MongoEngine Bug - https://github.com/MongoEngine/mongoengine/issues/1491
Using col.replace_one({‘_id': doc['_id']}, doc, True) instead.
The api is replace_one(filter, replacement, upsert=False, bypass_document_validation=False, collation=None, session=None).
Using upsert = True to insert a new doc if the filter find nothing.

Is get_validation_exclusions method of ModelSerializer in Django Rest Framework removed in latest versions?

While running the below code:
class PostSerializer(serializers.ModelSerializer):
author = UserSerializer(required=False)
def get_validation_exclusions(self):
exclusions = super(PostSerializer, self).get_validation_exclusions()
return exclusions + ['author']
I am getting the error Column 'author' cannot be null. When I checked online for documentation, this method is not available since 3.0 release (link: http://www.cdrf.co/3.3/rest_framework.serializers/ModelSerializer.html). Please let me know the alternative for this method supported in latest version.
You'll likely want to set the allow_null=True. required=False will only work if the key isn't defined at all.
In the latest version, required=False fields are automatically excluded.
This is discussed in more detail in this (closed) issue.
I'd recommend updating to the latest version.

get_or_create: is it a 'get' or a 'create'?

AFAIK, peewee's Model.get_or_create() doesn't return a flag that indicates a creation, unlike django's get_or_create(). Is there a good way to check if an instance returned by get_or_create() is freshly created?
Thanks
There's a section in the docs that should hopefully be helpful: http://docs.peewee-orm.com/en/latest/peewee/querying.html#get-or-create
If the docs are lacking, please let me know and I'll be happy to improve them.
http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get_or_create
classmethod get_or_create(**kwargs)
Attempt to get the row matching the given filters. If no matching row is found, create a new row.
Parameters:
kwargs – Mapping of field-name to value.
defaults – Default values to use if creating a new row.
Returns:
Tuple of Model instance and boolean indicating if a new object was created.
It also warns you that race conditions are possible with this method, and even gives you an example without using the method:
try:
person = Person.get(
(Person.first_name == 'John') &
(Person.last_name == 'Lennon'))
except Person.DoesNotExist:
person = Person.create(
first_name='John',
last_name='Lennon',
birthday=datetime.date(1940, 10, 9))
According to source code, no way to find out. Also, according to documentation, it is not recommended to use this method.
I suggest to use try/except/else clause.

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

Categories