Trying to upsert document in flask_MongoEngine - mongoengine

I've currently got a model:
class Ticket(db.Document):
name = db.StringField #issue.key
project = db.StringField() #issue.fields.project.key
issue_type = db.StringField() #issue.fields.issuetype.name
summary = db.StringField() #issue.fields.summary
description = db.StringField() #issue.fields.description
created = db.DateTimeField() #issue.fields.created
updated = db.DateTimeField() #issue.fields.updated
And some code that attempts to upsert:
Ticket.objects(name=name).update(
upsert = True,
name = name,
project = project,
issue_type = issue_type,
summary = summary,
description = description,
created = created,
updated = updated
)
And I'm getting this error message:
mongoengine.errors.InvalidQueryError: Cannot resolve field "name"
With the relevant bit saying the error occurs in
updated = updated
So far I've tried re-naming the fields of my variables and my model, but the error message remains the same. Sorry for asking if there's an in my face answer I'm blind to.
Update: If I delete name = name from the update it works fine. I renamed name to title and re-added it and it does not work. I am thoroughly confused.

I'm a moron and left off parens on name in the model.

Related

exiting lot_id in stock.move.line, showing same value from compute field

I got some issue that lot_name is not showing same value from another compute field in same recordset, stock.move.line. below is my code:
class StockMoveLine(models.Model):
_name = 'stock.move.line'
_inherit = 'stock.move.line'
lotter = fields.Char(string="Supplier Lot", compute='_compute_partner')
def _compute_partner(self):
if not self.lotter:
partner_id = self.env['stock.picking'].search([('name','=',self.reference)]).partner_id.id
self.lotter = str(partner_id)
if self.lot_name == "":
self.lot_name = self.lotter
else:
self.lot_name = "blank"
the lot_name had been already existed in base module field. So I would like to show partner_id in lot_name field as well. now I only see it in my new compute fieldl. I tried using #api.onchange but it is only work when the textfield of lotter is lost focus. how can I do to show the same value on both lotter and lot_name fields if there is no value earlier?
Add store=True in your field.Because compute field is not stored in your database.
lotter = fields.Char(string="Supplier Lot", compute='_compute_partner', store=True)

dynamo Db contains

I am very new to dynamodb, i got stuck up with a situation here. I am working on a code which is already available here. My requirement is I want to change my query to add a filter.
My current code is
reqObj.TableName = config.storeTableName;
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND #state = :stateName",
reqObj.ExpressionAttributeNames = {"#state": "state"};
reqObj.ExpressionAttributeValues= {":isActive": true, ":isDeleted": false , ":city": cityName , ":stateName" : region_code},
I want to check whether a specific value is there in city, i browsed and found out CONTAINS parameter will be suitable. But don't know where to add
Suppose i want to check whether the city contains a value "LOS ANGELES", where the code should be placed in the above code.
will It Be like this
reqObj.TableName = config.storeTableName;
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND CONTAINS(city = :city) AND #state = :stateName",
reqObj.ExpressionAttributeNames = {"#state": "state"};
reqObj.ExpressionAttributeValues= {":isActive": true, ":isDeleted": false , ":city": cityName , ":stateName" : region_code},
Thanks
I got it myself, I have to change my query like this
reqObj.FilterExpression = "isActive = :isActive AND isDeleted = :isDeleted AND CONTAINS(city, :city) AND #state = :stateName",
contains, is a function which will have the list of values , with the key value along with it
Thanks

Get FileDownloadUrl from attachment (Agile PLM)

I've been following the code samples included in Oracle document E15930_01 (Agile PLM Core Web Services User Manual). The samples are in Java, but I've translated what I need to .NET for the project I'm working on.
I can search for an object and return its attachments. I can get all the attachment properties except the one I need, fileDownloadUrl. This field is always blank.
Sample code follows. I thought by setting the property of allFiles to false and downloadUrl to true, I should get a download URL, but I don't. This code returns all the properties for the attachment except the one I want. Any thoughts on what I'm doing wrong?
AttachmentService svc = new AttachmentService();
svc.Credentials = credentials;
AgileGetFileAttachmentRequest[] req2 = InitializeArray<AgileGetFileAttachmentRequest>(1);
AgileFileAttachmentRequestType[] attachments = InitializeArray<AgileFileAttachmentRequestType>(1);
req2[0].classIdentifier = "MyIdentifier";
req2[0].objectNumber = "1234567890";
req2[0].allFiles = false;
req2[0].downloadUrl = true;
req2[0].attachments = attachments;
attachments[0] = new AgileFileAttachmentRequestType();
int rowId = getRowId(tt);
attachments[0].rowId = rowId;
GetFileAttachmentRequestType get = new GetFileAttachmentRequestType();
get.requests = req2;
GetFileAttachmentResponseType resp2 = svc.getFileAttachment(get);
AgileFileAttachmentResponseType[] attchResp = InitializeArray<AgileFileAttachmentResponseType>(1);
attchResp = resp2.responses[0].attachment;
Posting this in case someone else needs to do this or I need to do it later.
I found the data I needed. The download URLs are generated based on XML values in several fields in the database. They're the folder name, filename and FolderVersion on the row you're looking at. You need to parse the XML and retrieve the values to generate the link.
You can get the pattern for the download link through the Get Shortcut button.

Getting "Value does not fall within the expected range" when creating a new discussion with CSOM

I'm using the SharePoint 2013 client object model.
I'm getting a Microsoft.SharePoint.Client.ServerException that says: "Value does not fall within the expected range" when running _context.ExecuteQuery(). The code works as long as I comment out the statement entry["Author"] = authorValue;:
entry["Body"] = post.Body;
entry["Created"] = post.Created;
entry["Modified"] = post.Modified;
FieldUserValue authorValue = new FieldUserValue();
User author = _context.Web.EnsureUser("Mr. X");
_context.Load(author);
_context.ExecuteQuery();
authorValue.LookupId = author.Id;
entry["Author"] = authorValue;
entry.Update();
_context.ExecuteQuery();
"Author" is a valid field name. I also read about increasing "List View Lookup Threshold" to a value of 20 in http://dotnetfollower.com/wordpress/2012/05/sharepoint-value-does-not-fall-within-the-expected-range-exception-in-spfieldmap-getcolumnnumber/. But that value is already set to 5000.
I also checked the value of entry["Author"] without setting it explicitly (entry["Author"] = authorValue commented out) by adding this two statements:
_context.Load(entry);
_context.ExecuteQuery();
It is of type Microsoft.SharePoint.Client.FieldUserValue and it's LookupId property value is equal to authorValue.LookupId.
What did I miss?

SubSonic 3 doesn't honor schemas for update

I am not running Mike's latest code because it does not build and he didn't update the templates to generate code for the new Load with columns he added. So I am one revision back in the source.
My database has tables in multiple schemas and they would not update properly.
In SubSonic.Query Update.cs I needed to change the constructor. I include some lines for context but I had to change line 122 to add tbl.SchemaName so that the correct DatabaseTable constructor was called and the schema name was carried through.
From this:
public Update(ITable table)
{
_query = new SqlQuery(table.Provider);
_provider = table.Provider;
_query.QueryCommandType = QueryType.Update;
ITable tbl = table;
DatabaseTable dbTable = new DatabaseTable(tbl.Name, _provider, tbl.ClassName);
dbTable.Columns = tbl.Columns;
_query.FromTables.Add(dbTable);
}
To this:
public Update(ITable table)
{
_query = new SqlQuery(table.Provider);
_provider = table.Provider;
_query.QueryCommandType = QueryType.Update;
ITable tbl = table;
DatabaseTable dbTable = new DatabaseTable(tbl.SchemaName, tbl.Name, _provider, tbl.ClassName);
dbTable.Columns = tbl.Columns;
_query.FromTables.Add(dbTable);
}
Is there a question here? This sounds like it needs to go on SubSonic's mailing list or as an issue in SubSonic's github page: http://github.com/subsonic/SubSonic-3.0

Resources