jira-python getting custom field's value from an issue-link - python

I'm trying to get the value of an issue link's custom field.
I know how to do it in a regular sub-task, but with issue-link, I can't get it.
This is how I get a custom field's value in a Sub Task:
getattr(issue.fields, name_map[fields[0]])
And when I try it with issue link, like this:
getattr(**issue_link**.fields, name_map[fields[0]])
I get: AttributeError: type object 'PropertyHolder' has no attribute 'customfield_18697'
What's interesting, I can update the custom field's value, like this:
issue_link.update(fields={name_map["Field1"]:"ABC"})
Why can I update but not get the value?
Thanks in advance

Found the answer in https://community.atlassian.com/t5/Jira-questions/Get-custom-fields-from-linked-issues-with-Jira-API/qaq-p/1148453
Needs to be done with a rest call, and not through the API

Related

Type error when accessing Django request.POST

I'm attempting to build an XML document out of request.POST data in a Django app:
ElementTree.Element("occasion", text=request.POST["occasion"])
PyCharm is giving me an error on the text parameter saying Expected type 'str', got 'Type[QueryDict]' instead. I only bring up PyCharm because I know its type checker can be overzealous sometimes. However, I haven't been able to find anything about this issue specifically.
Am I doing something wrong? Or should I try to silence this error?
Assuming you're not posting anything unusual, like json, request.POST['occasion'] should return a string, either the field 'occasion' or the last value of the list submitted with that name (or an error, if empty. Use request.POST.get('occasion') to avoid).
There are apparently some httprequest related issues with pycharm, but the way to doublecheck if this is happening here would be to print out and/or type check request.POST['occasion'] prior to that line to make sure of what it returns, eg:
occasion = request.POST['occasion']
print(type(occasion), occasion)
ElementTree.Element("occasion", text=occasion)
In the last line, using a variable assigned ahead of time might be a simple way to remove the pycharm error without turning off warnings, depending on your tolerance for extra code.

How to access self.context property using a variable in flask

I want to access a property exist in the self.context using a variable. I have a variable name "prop" and it contains a value and it is already set in the self.context. I am using Flask Restplus framework.
prop = 'binding'
If I try to access this property like below then it gives me an error:
Object is not subscriptable
I want to know if there is any way to get the value? Like doing this:
print(self.context[prop])
I only get one solution don't know if its correct or not, I tried this :
self.context.__getattribute__(prop)
There are two ways to do this, the simplest is using getattr:
getattr(self.context, prop)
This function internally calls __getattribute__ so it's the same as your code, just a little neater.
However, you still have the problem that you probably only want to access some of the context, while not risking editing values set by different parts of your application. A much better way would be to store a dict in context:
self.context.attributes = {}
self.context.attributes["binding"] = False
print(self.context.attributes[prop])
This way, only certain context variables can be accessed and those that are meant to be dynamic don't mess with any used by your application code directly.

PubsubMessage publish_time gets saved as DatetimeWithNanoseconds

I'm trying to instantiate the following PubsubMessage:
timestamp = Timestamp()
timestamp.GetCurrentTime()
message = pubsub_v1.types.PubsubMessage(
data=b'{"id": 123}',
attributes={"some_attribute": "abcd"},
message_id="1",
publish_time=timestamp,
)
When I inspect the timestamp variable, it is of type Timestamp with seconds and nanos attributes, just as expected. However when I inspect message.publish_time I get a DatetimeWithNanoseconds object instead which does not have the aforementioned attributes so I get an error later in my code (because of this line in google-pubsub)
I've checked google's docs but I can't seem to find anything like this. Any help is appreciated.
Ok, so it seems that when passing a PubsubMessage instance to the constructor of the Message class, you can actually do the following:
message=message._pb
I noticed this in this line of the google-pubsub repo
By passing the message as its ._pb attribute you don't get an exception when trying to access message.publish_time.seconds or message.publish_time.seconds. I'm not sure why this is the case but it solved my problem. I'll add an update if I find more info on this.

Odoo v9 - Using Onchange, how do you clear what is already entered in a field?

I am extending product.template, and I've added a field called uom_class. When I change this field when editing a product, I'd like to clear what is entered in the Many2One field called "Unit of Measure" (uom_id in product.template). I am doing this because I am also changing the domain for the uom_id, and the existing selection ("Units" by default) will probably not be in that domain.
I've tried the following, as suggested for earlier versions, but it did not work.
#api.onchange('uom_class')
def onchange_uom_class(self):
# [...] not shown: previously set new domain for uom_id
result['value'] ={'uom_id':False}
return result
I've seen other posts suggest I need to add assign it an empty product.uom record, but I have no idea how to do that. Any help would be greatly appreciated.
Well, I figured this one out.
I just declared
uom_id = False
For some reason, returning the domain works, but not returning the value. Either that, or I just have no idea what I'm doing and I'm returning the value wrong... which is entirely possible.

When does .save() create an object?

I have the code:
name = MakesiteNameForm(datdict)
if name.is_valid:
name.save()
datsite = Makesite.objects.get(sitename=request.POST['sitename'])
datsite.ref_id.add(RefID.objects.create(url=request.POST['url'],description=request.POST['description']))
datsite.save()
So i have this bit of code what I want to use to create and save some manytomany items but when I try using this method is says that Makesite matching query does not exist. which i think means it hasn't saved but then later I call site = Makesite.objects.all() and I can clearly see the value of what request.POST['sitename'] is sitting inside the querydict. So is there anyway to query this better? or is there something about the save() i missing?
Edit: that form saves a value sitename values into the Makesite table
The save() call doesn't create objects, it just saves the object to the database, inserting a new row in case it's a new object, or updating it.
First, form.is_valid() is a method, but you're not calling it, so you're always trying to save name. That may or may not be related to your error, but it's wrong anyway, and maybe that's where the query error is coming from, not the get() call below. Fix it and see what happens.

Categories

Resources