Giter VIP home page Giter VIP logo

Comments (5)

spitty avatar spitty commented on June 13, 2024

Hi @kaseyreed,

Are you using java-dataloader:2.0.2?
Could you please attach exception with stacktrace to this issue?

If it possible please provide us with minimal reproducible code example.

from java-dataloader.

kaseyreed avatar kaseyreed commented on June 13, 2024

@spitty

Yes, we are using java-dataloader:2.0.2

Here is a stacktrace:

java.lang.ClassCastException: com.myCompany.MyType cannot be cast to org.dataloader.Try
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
	at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1962)
	at org.dataloader.DataLoader.lambda$dispatchQueueBatch$3(DataLoader.java:328)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
	at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1595)
	at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)
	at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

from java-dataloader.

bbakerman avatar bbakerman commented on June 13, 2024

@kaseyreed - the Try types returned from the batch loader are unpacked into either errors or data values.

From this exception stack trace I cant see it as being cause by an action of dataloader code. Can you expand the stack trace

from java-dataloader.

bbakerman avatar bbakerman commented on June 13, 2024

I am going to close this issue as no activity has been done on it

from java-dataloader.

deverant avatar deverant commented on June 13, 2024

Hey all, I know I am resurrecting a very old issue, but since I just stumbled upon this error I figured I'd leave a note for anyone else that gets caught by this.

The issue happens if you have configured your dataloader to not do batching. In this cases the load command actually returns type Try<T> response back to you. If you need a non-batching dataloader you just need to take that into account in your code.

For the developers: The issue is that for non-batching dataloaders the load command is executed directly here:

CompletableFuture<V> future = new CompletableFuture<>();
if (batchingEnabled) {
loaderQueue.add(new LoaderQueueEntry<>(key, future, loadContext));
} else {
stats.incrementBatchLoadCountBy(1);
// immediate execution of batch function
future = invokeLoaderImmediately(key, loadContext);
}
. This bypasses the code that opens up the Try object, which only happens when dispatching the queue:
private CompletableFuture<List<V>> dispatchQueueBatch(List<K> keys, List<Object> callContexts, List<CompletableFuture<V>> queuedFutures) {
stats.incrementBatchLoadCountBy(keys.size());
CompletionStage<List<V>> batchLoad = invokeLoader(keys, callContexts);
return batchLoad
.toCompletableFuture()
.thenApply(values -> {
assertResultSize(keys, values);
List<K> clearCacheKeys = new ArrayList<>();
for (int idx = 0; idx < queuedFutures.size(); idx++) {
Object value = values.get(idx);
CompletableFuture<V> future = queuedFutures.get(idx);
if (value instanceof Throwable) {
stats.incrementLoadErrorCount();
future.completeExceptionally((Throwable) value);
clearCacheKeys.add(keys.get(idx));
} else if (value instanceof Try) {
// we allow the batch loader to return a Try so we can better represent a computation
// that might have worked or not.
Try<V> tryValue = (Try<V>) value;
if (tryValue.isSuccess()) {
future.complete(tryValue.get());
} else {
stats.incrementLoadErrorCount();
future.completeExceptionally(tryValue.getThrowable());
clearCacheKeys.add(keys.get(idx));
}
} else {
V val = (V) value;
future.complete(val);
}
}
possiblyClearCacheEntriesOnExceptions(clearCacheKeys);
return values;
}).exceptionally(ex -> {
stats.incrementBatchLoadExceptionCount();
for (int idx = 0; idx < queuedFutures.size(); idx++) {
K key = keys.get(idx);
CompletableFuture<V> future = queuedFutures.get(idx);
future.completeExceptionally(ex);
// clear any cached view of this key because they all failed
dataLoader.clear(key);
}
return emptyList();
});
}

I don't know if this is intended behavior or not so I just leave the comment for now. :) Thanks for all your work on graphql-java!

from java-dataloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.