In py2neo, how do I know if a push() worked? - neo4j

I'm updating a node and pushing it:
remote_graph.push(node)
push() seems to return nothing. How can I tell if the push works? In my test code, I ought to be violating a unique constraint in Neo4J.
How can I tell using py2neo? I expected an exception.
When I enter the equivalent cypher into the Neo4J web tool, I get the following exception:
Node 322184 already exists with label VERSION and property "version"=[1.436818928448956E9]
which is what I expected.
Edit -
What I expected to get back was an indicator of whether the operation worked or not. I think push() accepts an array of nodes, so an array of results would be sensible. I don't know what the indicator would have within it since I don't know what is available. An array of strings would be fine, with each string being a failure reason, or "OK".

Generally speaking, the design of this API is: if it returns OK, you can assume everything has worked as expected, if an error is raised, that error will contain details of what went wrong. Therefore, absence of error should usually be interpreted as a signal of success.
That said, if you believe that your push has failed and no error has been raised, there is a bug in py2neo. For debugging, you can check the state of the database after your push by using the browser and then if you're able to recreate this scenario in a standalone piece of code, please raise an issue on GitHub and I will be happy to fix it.

Related

Proper way to return error from within a mutateAndGetPayload

I am doing a number of business logic checks within the mutateAndGetPayload function of a relay mutation using the graphql-relay library. For any of these checks that fail I have an else clause that will throw an error, ig throw('You do not have permission to delete this resource');, however, when that happens, I get the error Cannot set property 'clientMutationId' of undefined returned to the frontend instead of the error I'm trying to return. It seems that I'm seeing this error because I'm not returning something this mutation cares about (or a promise that resolves to one), so I'm a little stumped ... what's the proper way to throw/return errors back to the client here?
One way is to use the GraphQLError Type
Working in NodeJS on the back end we have used the following library:
https://github.com/graphql/graphql-js/tree/master/src/error
However, what we have ended up using is a library that provides more flexibility:
https://github.com/kadirahq/graphql-errors
Either of these would be the best place to start.

TFS API - Object not set to reference of an object Error

I'm using the TFS api to pull data on some projects into a localized database. Recently this stopped working. and gave us this error.
Object Not Set to Reference of an Object
AND
Null reference exception at the Domain level (this fails the moment it connects)
We are pulling down the hierarchy.
Domain - Collection - Project - Requirements... etc.
Debugging I find that I the code can see the domains but not grab them or anything under them. I am perplexed as to what might have caused this. Our dlls are all up to date with the version of TFS being used (Version 12). Thought it might be a credential issue, but this occurs with any credentials used. I've read that it could be a cache issue with the server side credentials somehow. But I do not have access to this.
I would post code, but I am unsure which part would be the most helpful as the connector method works... just fails when it connects so the problem appears to be elsewhere.
Thoughts?
UPDATE:
I have detected the line of code where we have a failure... but walking through it the code detects all TFS items. Domains, test cases, projects. Everything.
But will always return the Null Reference Exception. Keep in mind this has worked seemlessly for months.
Domain dbDomain = server.Domains.DefaultIfEmpty(null).FirstOrDefault(a => a.DomainId.Equals(domain.DomainId));
Okay so the stupid mistake was in the Lambda expression. It was returning null because it was trying to calculate before a value was assigned. Silly me.
Domain dbDomain = server.Domains.DefaultIfEmpty(null).FirstOrDefault(a => a.DomainId.Equals(domain.DomainId));
Should be:
Domain dbDomain = server.Domains.Where(a => a.DomainId.Equals(domain.DomainId))DefaultIfEmpty(null).FirstOrDefault();

Ruby on Rails: What is stale object and it's features?

In my application i got the error as con't update stale object. I don't know about this object. When it will create and why it was called a stale object. I want to know. Is it used in Only in ROR or other languges are also uses, this object and purpose?
According to the documentation:
http://api.rubyonrails.org/classes/ActiveRecord/StaleObjectError.html
Reason of Stale object exception is:
Record is stale when it's being saved in another query after instantiation, for example, when two users edit the same wiki page and one starts editing and saves the page before the other.
Solution: To avoid this exception use the locking system:
http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html
In my application multiple threads to be able to edit the same work -> version -> element record. its detecting error and raising the suitable error.
I typically did to handle the error:
I print a flash message such as "Sorry, please try after someone time, someone else editing this working version element".
element.lock_version = Document::Element.find(element.id).lock_version
element.save!
For example, such as detecting that one edit changed the element's type, where as the other edit changed the element's name by different creator, and then code of the two record should be merged done in one save.
In general, I used to element.reload to fetch a fresh version of the element.
worked fine!!

Metadata bug in Breeze 1.3.1? (Inheritence)

Trying out Breeze 1.3.1 and we've hit a problem. When trying to load the metadata, we get this error:
"Error: Metadata import failed for api/securitychart/Metadata; Unable to process returned metadata:Unable to locate a 'Type' by the name: Vehicle:#Project.Model.Entities"
Just for clarification, the entity "Vehicle" is the base type from which two other entities "Motorbike" and "Car" inherit.
We've digged up a bit through Breeze's code and found that the JSON returned from the ContextProvider.Metadata() method returns the array of entityTypes in the following order:
And the error pops out when trying to parse then entity data for Motorbike.
Without having much idea what was going on, we guessed that the base class Vehicle was not available when trying to parse the metadata for Motorbike, so we manipulated the array to let it process first the base class Vehicle. After doing this, this error no longer appears, but there's a different one: "bad navigation properties".
Can you guys please give us a clue about how to proceed from here?
Edit: As of v 1.3.2, this bug should be fixed. Please post back here to either confirm that it works or that you still have an issue.
Edit: Ok, this is a bug and will be fixed in the next release. And thanks for the repro metadata, it really helped.
Can you send me an email with the "broken" metadata ( the json returned from the server) at breeze.ideablade.com ( with Attn: Jay Traband somewhere in the email). and I'll try to get back to you as soon as possible.

Parsing a CSV for Database Insertion when Formatted Incorrectly

I recently wrote a mailing platform for one of our employees to use. The system runs great, scales great, and is fun to use. However, it is currently inoperable due to a bug that I can't figure out how to fix (fairly inexperienced developer).
The process goes something like this...
Upload a CSV file to a specific FTP directory.
Go to the import_mailing_list page.
Choose a CSV file within the FTP directory.
Name and describe what the list contains.
Associate file headings with database columns.
Then, the back-end loops over each line of the file, associating the values with a heading, and importing these values into a database.
This all works wonderfully, except in a specific case, when a raw CSV is not correctly formatted. For example...
fname, lname, email
Bob, Schlumberger, bob#bob.com
Bobbette, Schlumberger
Another, Record, goeshere#email.com
As you can see, there is a missing comma on line two. This would cause an error when attempting to pull "valArray[3]" (or valArray[2], in the case of every language but mine).
I am looking for the most efficient solution to keep this error from happening. Perhaps I should check the array length, and compare it to the index we're going to attempt to pull, before pulling it. But to do this for each and every value seems inefficient. Anybody have another idea?
Our stack is ColdFusion 8/9 and MySQL 5.1. This is why I refer to the array index as [3].
There's ArrayIsDefined(array, elementIndex), or ArrayLen(array)
seems inefficient?
You gotta code what you need to code, forget about inefficiency. Get it right before you get it fast (when needed).
I suppose if you are looking for another way of doing this (instead of checking the array length each time, although that really doesn't sound that bad to me), you could wrap each line insert attempt in a try/catch block. If it fails, then stuff the failed row in a buffer (including the line number and error message) that you could then display to the user after the batch has completed, so they could see each of the failed lines and why they failed. This has the advantages of 1) not having to explicitly check the array length each time and 2) catching other errors that you might not have anticipated beforehand (maybe a value is too long for your field, for example).

Resources