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

Replace to gopkg.in/yaml with github.com/goccy/go-yaml (slightly breaking change) #8822

Open
bep opened this issue Jul 29, 2021 · 4 comments · May be fixed by #13033
Open

Replace to gopkg.in/yaml with github.com/goccy/go-yaml (slightly breaking change) #8822

bep opened this issue Jul 29, 2021 · 4 comments · May be fixed by #13033
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented Jul 29, 2021

Add this to have something to track this with.

The main blocker I see for this is that it's not possible to control location/timezone for dates without that information.

package main

import (
	"fmt"
	"log"

	v2 "gopkg.in/yaml.v2"
	v3 "gopkg.in/yaml.v3"
)

var data = `
d: 2021-07-15

`

func main() {
	mv2 := make(map[string]interface{})
	err := v2.Unmarshal([]byte(data), &mv2)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Printf("--- mv2: %T %v \n", mv2["d"], mv2["d"])

	mv3 := make(map[string]interface{})
	err = v3.Unmarshal([]byte(data), &mv3)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Printf("--- mv3: %T %v \n", mv3["d"], mv3["d"])
}

Prints:

--- mv2: string 2021-07-15 
--- mv3: time.Time 2021-07-15 00:00:00 +0000 UTC 

Note that v2 isn't perfect, either, but that at least allows us to handle known dates (e.g. the front matter dates).

@bep bep added this to the v0.87 milestone Jul 29, 2021
@bep
Copy link
Member Author

bep commented Jul 29, 2021

See go-yaml/yaml#770

@bep bep modified the milestones: v0.87, v0.88 Jul 30, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep added this to the v0.121.0 milestone Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@jmooring
Copy link
Member

jmooring commented Feb 13, 2024

Everyone once in a while a user gets burned by "on/off/yes/no" keys. This happened again yesterday. While I understand why this is blocked, I must say I have little sympathy for unqualified dates. If we could start over, or break some eggs, I'd place every unqualified date in Etc/UTC.

@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, Unscheduled Oct 23, 2024
@jmooring
Copy link
Member

jmooring commented Nov 9, 2024

Consider replacing github.com/go-yaml/yaml (last updated 2.5 years ago) with github.com/goccy/go-yaml which, at the moment, is actively maintained with 1.2k stars.

What we get:

  • Eliminates the Norway problem. Booleans are true|True|TRUE|false|False|FALSE. This would be a breaking change for anyone who has been using any of these to represent a boolean value: y|Y|yes|Yes|YES|n|N|no|No|NO|on|On|ON|off|Off|OFF.

  • Ability to disallow duplicate keys instead of letting the last one win (see #8427).

  • Helpful error messages:

    Error: error building site: process: readAndProcessContent: "/home/jmooring/code/hugo-testing/content/_index.md:43:1": failed to unmarshal YAML: [4:15] unexpected key name
       1 | title: home
       2 | date: 2024-11-09
       3 | params:
    >  4 |   event_date: 2024-12-31T07:43:15-08:00
       5 |     foo: bar
    
  • The problem we ran into when looking at upgrading to github.com/go-yaml/yaml v3 does not seem to apply here. See v3: No way to control location of short dates go-yaml/yaml#770.

@bep bep changed the title Update to gopkg.in/yaml.v3 Replace to gopkg.in/yaml with github.com/goccy/go-yaml (slightly breaking change) Nov 13, 2024
@bep bep modified the milestones: Unscheduled, v0.138.0 Nov 13, 2024
@bep
Copy link
Member Author

bep commented Nov 13, 2024

I must say I have little sympathy for unqualified dates.

Just to be clear, this is a very common "unqualified date" (for one, it's very easy to type, which I have sympathy for ...):

publishDate: 2021-07-15

Having the above mean UTC, would create very surprising beheaviour.

@bep bep self-assigned this Nov 13, 2024
bep added a commit to bep/hugo that referenced this issue Nov 13, 2024
Out of the box it's significantly slower than what we had:

```
pkg: github.com/gohugoio/hugo/parser/metadecoders
cpu: Apple M1 Pro
                   │ master.bench │        fix-goyaml-8822.bench         │
                   │    sec/op    │    sec/op      vs base               │
DecodeYAMLToMap-10   6.758µ ± 20%   10.505µ ± 25%  +55.43% (p=0.000 n=8)

                   │ master.bench │        fix-goyaml-8822.bench         │
                   │     B/op     │     B/op       vs base               │
DecodeYAMLToMap-10   8.461Ki ± 0%   11.021Ki ± 0%  +30.26% (p=0.000 n=8)

                   │ master.bench │       fix-goyaml-8822.bench        │
                   │  allocs/op   │ allocs/op   vs base                │
DecodeYAMLToMap-10     108.0 ± 0%   281.0 ± 0%  +160.19% (p=0.000 n=8)
```

Fixes gohugoio#8822
@bep bep modified the milestones: v0.138.0, v0.139.0, v0.140.0 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants