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

go: dates are mistreated as strings #2659

Closed
1 of 5 tasks
iliapolo opened this issue Mar 7, 2021 · 1 comment · Fixed by #2730
Closed
1 of 5 tasks

go: dates are mistreated as strings #2659

iliapolo opened this issue Mar 7, 2021 · 1 comment · Fixed by #2730
Assignees
Labels
bug This issue is a bug. compliance Missing or broken compliance tests effort/medium Medium work item – a couple days of effort language/go Regarding GoLang bindings p1

Comments

@iliapolo
Copy link
Contributor

iliapolo commented Mar 7, 2021

🐛 Bug Report

Golang generated code results in Date arguments treated as plain strings.

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Golang

General Information

  • JSII Version: ALL
  • Platform: ALL

What is the problem?

Consider the following TS code:

public set dateProperty(value: Date) {
// https://stackoverflow.com/a/643827/737957
if (Object.prototype.toString.call(value) !== '[object Date]') {
throw new Error(`not a date: ${value as any} type=${typeof value}`);
}
this.dateValue = value;

The resulting Golang code would be:

func (a *allTypes_jsiiProxy) SetDateProperty(val string) {
	_jsii_.Set(
		a,
		"dateProperty",
		val,
	)
}

Which causes a deserialization error:

test panicked: "Expected Date, got \"12345\""

Stemmed from here:

if (!isWireDate(value)) {
throw new Error(`Expected Date, got ${JSON.stringify(value)}`);
}

This seems to be a known issue, as evident here:

// TODO: Resolve "time" package dependency where needed and change to "time.Time"
date: 'string',

Verbose Log

@iliapolo iliapolo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. compliance Missing or broken compliance tests effort/medium Medium work item – a couple days of effort p1 language/go Regarding GoLang bindings and removed needs-triage This issue or PR still needs to be triaged. labels Mar 7, 2021
RomainMuller added a commit that referenced this issue Mar 22, 2021
Implements the correct code generation flow & runtime logic to correctly
handle jsii date values as *time.Time instances.

Fixes #2659
@mergify mergify bot closed this as completed in #2730 Mar 24, 2021
mergify bot pushed a commit that referenced this issue Mar 24, 2021
Implements the correct code generation flow & runtime logic to correctly
handle jsii date values as *time.Time instances.

Fixes #2659



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. compliance Missing or broken compliance tests effort/medium Medium work item – a couple days of effort language/go Regarding GoLang bindings p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants