Very similar to #27517, but it looks like this issue has not been fixed for the Path variant of DataBufferUtils.write, see the following code (similar to the example snippet from #27517 but writing to a Path instead of an OutputStream):

DataBufferUtils.read(new ByteArrayResource("test".getBytes()), new NettyDataBufferFactory(new PooledByteBufAllocator()), 1024)
        .transformDeferredContextual((f, ctx) -> {
            System.out.println("1: " + ctx.getOrDefault("key", "EMPTY"));
            return f;
        })
        .transform(f -> DataBufferUtils.write(f, Path.of("test")))
        .transformDeferredContextual((f, ctx) -> {
            System.out.println("2: " + ctx.getOrDefault("key", "EMPTY"));
            return f;
        })
        .contextWrite(Context.of("key", "TEST"))
        .subscribe();

Expected result:

2: TEST
1: TEST

Actual result:

2: TEST
1: EMPTY

The context is lost here: https://github.com/spring-projects/spring-framework/blob/508cc346e098266a84d64281635344f8c6231281/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java#L367-L369

Passing sink's context into the subscribe() call would fix this isssue:

write(source, channel).subscribe(DataBufferUtils::release,
        sink::error,
        sink::success,
        Context.of(sink.contextView()));

Environment: * Spring Boot 2.7.2 * Spring Framework 5.3.22 * Project Reactor 3.4.21

Comment From: kzander91

Our workaround until this is fixed is to manually propagate the context:

Flux<DataBuffer> bufs = ...;
Path path = ...;
Mono<Void> write = Mono.deferContextual(ctx -> DataBufferUtils.write(bufs.contextWrite(ctx), path));

Comment From: poutsma

Fixed! Thanks for spotting this, @kzander91