"Automatic ReviewDb only available in request scope" error while executing gApi.changes().id(myId).current().review(input);

81 views
Skip to first unread message

Sharath Gupta

unread,
Jul 28, 2016, 5:09:28 PM7/28/16
to Repo and Gerrit Discussion
Hi


I am writing a plugin which needs the following requirement:


Plugin listens to particular event, on that event, create a new thread and from that new thread review a particular change using gApi.changes().id(myId).current().review(input); 

1)
I have a gApi instance in the plugin thread and when I try to pass gApi for the new thread, it receives null.


2)

I got the instance of RevisionApi in plugin thread as RevisionApi rApi = gApi.changes().id(myId).current(); and tried to pass rApi to the new thread. rApi was not null but got the following error when I tried to review using this command rApi.review(input);


com.google.inject.ProvisionException: Unable to provision, see the following errors:


1) Automatic ReviewDb only available in request scope

  at com.google.gerrit.server.util.ThreadLocalRequestContext$1.provideReviewDb(ThreadLocalRequestContext.java:70) (via modules: com.google.gerrit.server.config.GerritGlobalModule -> com.google.gerrit.server.util.ThreadLocalRequestContext$1)

  while locating com.google.gerrit.reviewdb.server.ReviewDb


1 error

at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)

at com.google.gerrit.server.change.PostReview.apply(PostReview.java:168)

at com.google.gerrit.server.change.PostReview.apply(PostReview.java:144)

at com.google.gerrit.server.api.changes.RevisionApiImpl.review(RevisionApiImpl.java:168)

at 




I am able to give the review from the plugin thread itself successfully but not from a new thread. 

PLease let me know how do I resolve this.


Thanks

Sharath

Edwin Kempin

unread,
Jul 29, 2016, 2:16:08 AM7/29/16
to Sharath Gupta, Repo and Gerrit Discussion
This code must be executed in a request context.
If you start a background thread you must create this context:
Get OneOffRequestContext injected and then do
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
      // call gApi

PLease let me know how do I resolve this.


Thanks

Sharath

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages