1

I upgraded my Apache Beam version from 2.34.0 to 2.41.0 and getting the following error when trying to build the template.

The error:

Exception in thread "main" java.lang.IllegalStateException: Value only available at runtime, but accessed from a non-runtime context: RuntimeValueProvider{propertyName=spannerInstanceId, default=defaultinstanceid}
        at org.apache.beam.sdk.options.ValueProvider$RuntimeValueProvider.get(ValueProvider.java:254)
        at org.apache.beam.sdk.io.gcp.spanner.SpannerConfig.withInstanceId(SpannerConfig.java:165)
        at .... my code constructing SpannerConfig ...

My code looks like this:

  private static SpannerConfig getValidatedSpannerConfig(MyCustomOptions options) {
    SpannerConfig spannerConfig =
        SpannerConfig.create()
            .withProjectId(options.getSpannerProjectId())
            .withInstanceId(options.getSpannerInstanceId())
            .withDatabaseId(options.getSpannerDatabaseId());
    spannerConfig.validate();
    return spannerConfig;
  }

Using Beam version <= 2.39.0 solving that issue.


Seems like the SpannerConfig withInstanceId method is causing this runtime read by calling get() ahead of time.
Is there a chance there is a bug in 2.40.0 and 2.41.0 versions of org.apache.beam:beam-sdks-java-io-google-cloud-platform ?

Decompiled version of 2.41.0 is:

  public SpannerConfig withInstanceId(ValueProvider<String> instanceId) {
    Preconditions.checkNotNull(instanceId);
    Preconditions.checkNotNull(instanceId.get()); // <<<<<< The problematic line
    return toBuilder().setInstanceId(instanceId).build();
  }

Decompiled version of 2.39.0 is:

  public SpannerConfig withInstanceId(ValueProvider<String> instanceId) {
    return toBuilder().setInstanceId(instanceId).build();
  }
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
jurl
  • 2,504
  • 1
  • 17
  • 20

1 Answers1

2

I believe there is a bug there, introduced in 2.40.0, where it tries to read a value when it's not yet accessible.

Alexey Romanenko
  • 1,353
  • 5
  • 11