"cypher.client" transaction issue in c# cant error and commited - neo4j

I'm using Cypher.Client Transaction in my queries.
my transaction is committed without problem. however in every create and update that runs OK, one of my relations doesn't update. i wonder if the problem is in my transaction or there is a bug in my code. how can i detect what went wrong?
Some of these transaction work properly , though . But there 's a problem .
sample open transaction:
var txClient = (ITransactionalGraphClient)aClient;
using (var tx = txClient.BeginTransaction())
{ my query!}
thanks.

Check your Match scope for extra relation which will cause the transaction no to be
commit.

Related

What does the querying of the transaction actually do?

I am wondering what does the querying if the connection is in transaction or not actually do ?
Example :
....
try
if not DATA_MODULE.ACRDatabase1.InTransaction then
DATA_MODULE.ACRDatabase1.StartTransaction;
....
DATA_MODULE.ACRDatabase1.Commit();
except
DATA_MODULE.ACRDatabase1.Rollback;
Does it temporarily stop the current transaction if it detects that there is another transaction going on and waits for the other transaction to complete and only then executes or what? Or does it just misfire (rollback) if there's another transaction detected?
Attempting to start a transaction which has already been started will raise an exception. The call to InTransaction simply determines if the transaction has already started or not and returns a True/False response.
I prefer this...it protects you if you have any problems while editing...and only rollback if you have a problem with the Commit. If any exception is raised after the StartTransaction...you will never get to the Commit. You will always run the finally and will make sure you are not in a Tranaction, if so Rollback. I try not to use Try Except, don't have to worry about the Raise
try
DATA_MODULE.ACRDatabase1.StartTransaction;
....
DATA_MODULE.ACRDatabase1.Commit();
finally
if DATA_MODULE.ACRDatabase1.InTransaction then
DATA_MODULE.ACRDatabase1.Rollback;
at the very least the code should be reraising the exception or your user will never know why the data is not saving. ReRaising Exception

ActiveRecord: update_all shows query in debug log, but doesn't execute in DB?

I've got the following update query running in a function called by a before_destroy callback in a Rails model:
Annotation.joins(:annotation_groups)
.where({'annotation_groups.group_id' => self.id})
.update_all({qc_approved: false}) if doc.in_qc?`
(I've also tried the following simpler version to see if another angle works: self.annotations.update_all({qc_approved: false}))
Both generate the below SQL query in "Server development log" (debugging in RubyMine):
UPDATE "annotations" SET "qc_approved" = 'f' WHERE "annotations"."id" IN (SELECT "annotations"."id" FROM "annotations" INNER JOIN "annotation_groups" ON "annotation_groups"."annotation_id" = "annotations"."id" WHERE "annotation_groups"."group_id" = 159)
However, as far as I can tell, that SQL never causes a DB update, even though the destroy process afterwards works fine. I can set a breakpoint directly after the statement and look at the database, and the qc_approved fields are still true. However, I can copy and paste the statement into a Postgres console and run it, and it updates the fields correctly.
Is anyone aware as to what would cause this behavior? Does before_destroy exist in its own strange alternate transactional universe that causes odd behavior like this? What scenario would cause the SQL to show up in the server log but not make it to the DB?
Thanks to the quick and helpful comments above confirming the nature of the callback inside the larger transaction, I figured it out.. despite the name, before_destroy was actually executing after dependent destroy calls, so that the joined annotation_group table row was destroyed before the UPDATE statement that relied on it was called in the transaction.
To be more specific, I added :prepend => true to the before_destroy definition so that it ran before the destroys as intended.

'save' does not work, tried flush and failOnError:true but no error was given

I'm trying to update a DB with flush:true for save() operations. The debugger showed that the status was updated, but when I use this sql
Select * from domain_name where id = 123
I'm still getting the old status.
I am using the Quartz plugin for running a scheduled cron job that reads from the same table:
DomainName.withTransaction{ status ->
try
{
DomainName name = DomainName.get(123)
name.status = "newstatus"
name.save(flush:true,failOnError:true)
}
catch(Exception rte)
{
log.error "Update failed with error ${rte.message}"
status.setRollbackOnly()
}
}
Has anyone encountered similar issues? There are no error on turning on hibernate log in config.groovy
debug 'org.hibernate.SQL'
'org.hibernate.transaction'
I experienced this issue. Turns out that the instance to update was being obtained via a dynamic finder. Once I used get(id) to obtain the instance the values were save to the database table.
During troubleshooting I turned on the sql logging. When the row was supposed to be updated no update statement was written to the console when the instance was obtained via the finder. Using get(id) the update statement was written to the console.
I think the problem resides before your given code block.
Did you pull that object with dirty checking (e.g. Domain.get()) before this transaction, which is still alive? My suggestion is to check your code carefully, detach from all dirty check (e.g. use Domain.discard()) and try again. That should solve your problem.
I was facing a similar problem. I was getting the object via a dynamic method. Then passing a property to another method. In the other method I was again getting the object by a dynamic finder.
I saved the domain object but it was not getting saved. I tried failOnError as well as flush but did not work.
I passed the domain object instead of using dynamic finder and it worked.

Automatic rollback without any error?

I'm unable to create a row in the DB. Rails apparently starts and then immediately rolls back the transaction without any errors. I'm using sqlite3.
logger.debug("creating billing name...")
BillingName.create() #also tried BillingName.new.save
logger.debug("...created")
Log file:
creating billing name...
^[[1m^[[36m (0.1ms)^[[0m ^[[1mbegin transaction^[[0m
^[[1m^[[35m (0.1ms)^[[0m rollback transaction
...created
select * from billing_name shows indeed no entry has been added. How can I tell why the transaction is being rejected?
You can check the errors after a save or valid?
billing_name = BillingName.new
billing_name.save # or billing_name.valid?
puts billing_name.errors.inspect
These are good answers that help you find the error by inspecting the model. I use those too.
But I've found that ActiveRecord doesn't always provide useful information, especially in callbacks. valid? will be true, errors will be empty, and the console won't show anything except the rollback. So, a good place to look is what is happening in those callbacks, specifically the before_create filter.
As someone who always uses the bang methods, I recently had a similar issue and could not debug it.
The only thing is, I had upgraded to rails 7.
Yup, so apparently, using return inside of a transaction block is no longer supported and will result in a rollback.
GITHUB: Deprecate committing a transaction exited with return or throw #29333

Saving updates to objects in rails

I'm trying to update one of my objects in my rails app and the changes just don't stick. There are no errors, and stepping through with the debugger just reveals that it thinks everything is updating.
Anyway, here is the code in question...
qm = QuestionMembership.find(:first, :conditions => ["question_id = ? AND form_id = ?", q_id, form_id])
qm.position = x
qm.save
For reference sake, QuestionMembership has question_id, form_id, and position fields. All are integers, and have no db constraints.
That is basically my join table between Forms and Questions.
Stepping through the code, qm gets a valid object, the position of the object does get changed to the value of x, and save returns 'true'.
However, after the method exits, the object in the db is unchanged.
What am I missing?
You may not be finding the object that you think you are. Some experimenting in irb might be enlightening.
Also, as a general rule when changing only one attribute, it's better to write
qm.update_attribute(:position, x)
instead of setting and saving. Rails will then update only that column instead of the entire row. And you also get the benefit of the data being scrubbed.
Is there an after_save?
Is the correct SQL being emitted?
In development log, you can actually see the sql that is generated.
For something like this:
qm = QuestionMembership.find(:first, :conditions => ["question_id = ? AND form_id = ?", q_id, form_id])
qm.position = x
qm.save
You should see something to the effect of:
SELECT * FROM question_memberships WHERE question_id=2 AND form_id=6 LIMIT 1
UPDATE question_memberships SET position = x WHERE id = 5
Can you output what sql you are actually seeing so we can compare?
Either update the attribute or call:
qm.reload
after the qm.save
What is the result of qm.save? True or false? And what about qm.errors, does that provide anything that makes sense to you? And what does the development.log say?
I have run into this problem rather frequently. (I was about to say consistently, but I cannot, as that would imply that I would know when it was about to happen.)
While I have no solution to the underlying issue, I have found that it seems to happen to me only when I am trying to update mysql text fields. My workaround has been to set the field to do something like:
qm.position = ""
qm.save
qm.position = x
qm.save
And to answer everyone else... when I run qm.save! I get no errors. I have not tried qm.save?
When I run through my code in the rails console everything works perfectly as evidenced by re-finding the object using the same query brings the expected results.
I have the same issue when using qm.update_attribute(... as well
My workaround has gotten me limping this far, but hopefully someone on this thread will be able to help.
Try changing qm.save to qm.save! and see if you get an exception message.
Edit: What happens when you watch the log on the call to .save!? Does it generate the expected SQL?
Use ./script/console and run this script.. step by step..
see if the position field for the object is update or not when you run line 2
then hit qm.save or qm.save!... to test
see what happens. Also as mentioned by Tim .. check the logs
Check your QuestionMembership class and verify that position does not have something like
attr_readonly :position
Best way to debug this is to do
tail -f log/development.log
And then open another console and do the code executing the save statement. Verify that the actual SQL Update statement is executed.
Check to make sure your database settings are correct. If you're working with multiple databases (or haven't changed the default sqlite3 database to MySQL) you may be working with the wrong database.
Run the commands in ./script/console to see if you see the same behavior.
Verify that a similar object (say a Form or Question) saves.
If the Form or Question saves, find the difference between the QuestionMembership and Form or Question object.
Turns out that it was emitting the wrong SQL. Basically it was looking for the QuestionMembeship object by the id column which doesn't exist.
I was under the impression that that column was unnecessary with has_many_through relationships, although it seems I was misguided.
To fix, I simply added the id column to the table as a primary key. Thanks for all the pointers.

Resources