Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing method to_json on struct type #12983

Closed
dududko opened this issue Feb 9, 2021 · 5 comments
Closed

missing method to_json on struct type #12983

dududko opened this issue Feb 9, 2021 · 5 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug

Comments

@dududko
Copy link

dududko commented Feb 9, 2021

Description of the problem / feature request:

Missing method to_json on struct type. This is a breaking change which is not documented, and it results in build failure of many bazel extensions including rules_docker

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

rule.bzl

def  my_rule_impl(ctx):
    s = struct()
    print(s.to_json())

my_rule = rule(
    implementation = my_rule_impl,
)

BUILD.bazel

load("//:rule.bzl", "my_rule")

my_rule(
    name = "my_target"
)

bazel build //:my_target

What operating system are you running Bazel on?

macOS Catalina 10.15.7

What's the output of bazel info release?

release 4.0.0

Have you found anything relevant by searching the web?

No

Any other information, logs, or outputs that you want to share?

bazel build //...
(19:10:58) INFO: Invocation ID: 724bb149-9541-4e98-b610-e620c46a1572
(19:10:59) INFO: Current date is 2021-02-09
(19:11:39) INFO: SHA256 (https://golang.org/dl/?mode=json&include=all) = 7008033e0ab99ec03d6eb9593445b9a94bec029ac91450ffb4318c059ca427dc
(19:12:15) ERROR: /Users/dududko/myproject/chart/frontend/test/test-frontend/BUILD.bazel:14:16: in container_layer_ rule //chart/frontend/test/test-frontend:layer:
Traceback (most recent call last):
	File "/private/var/tmp/_bazel_dududko/14485085ed56a1ffbc0109316724dc49/external/io_bazel_rules_docker/container/layer.bzl", line 232, column 42, in _impl
		unzipped_layer, diff_id = build_layer(
	File "/private/var/tmp/_bazel_dududko/14485085ed56a1ffbc0109316724dc49/external/io_bazel_rules_docker/container/layer.bzl", line 146, column 46, in build_layer
		ctx.actions.write(manifest_file, manifest.to_json())
Error: 'struct' value has no field or method 'to_json'
Available attributes: debs, empty_dirs, empty_files, empty_root_dirs, files, symlinks, tars
(19:12:15) ERROR: Analysis of target '//chart/frontend/test/test-frontend:layer' failed; build aborted: Analysis of target '//chart/frontend/test/test-frontend:layer' failed
(19:12:15) INFO: Elapsed time: 76.346s
(19:12:15) INFO: 0 processes.
(19:12:15) FAILED: Build did NOT complete successfully (259 packages loaded, 8837 targets configured)
    Fetching @com_github_aws_aws_sdk_go; fetching 25s
    Fetching @io_cirello_dynamolock; fetching 25s
    Fetching @com_github_stretchr_testify; fetching 25s
    Fetching @com_github_pelletier_go_toml; fetching 24s
@dmivankov
Copy link
Contributor

dmivankov commented Feb 13, 2021

258dfe9

  • The Starlark json module is now available.
    Use json.encode(x) to encode a Starlark value as JSON.
    struct.to_json(x) is deprecated and will be disabled by
    the --incompatible_struct_has_no_methods flag.

is --incompatible_struct_has_no_methods on?

@dmivankov
Copy link
Contributor

Shouldn't be on by default I think, looking at 4.0.0 release info https://blog.bazel.build/2021/01/19/bazel-4-0.html#starlark

@dududko
Copy link
Author

dududko commented Feb 13, 2021

I did not enable this option. I can confirm that build is successful if this option is explicitly disabled --incompatible_struct_has_no_methods=false.

@brandjon
Copy link
Member

Are you using --all_incompatible_changes? That would turn it on. Also check your bazelrc file.

@brandjon brandjon added P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Build-Language and removed breakage team-Starlark untriaged labels Feb 15, 2021
@dududko
Copy link
Author

dududko commented Feb 15, 2021

@brandjon yes I do
I totally forgot about this option.
Sorry for you time, you can close this ticket.

@dududko dududko closed this as completed Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) type: bug
Projects
None yet
Development

No branches or pull requests

4 participants