stac-utils / pystac

Python library for working with any SpatioTemporal Asset Catalog (STAC)

Home Page:https://pystac.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stac_extensions is output in arbitrary order

philvarner opened this issue · comments

The context of this is a set of tests I have that take an input of metadata and/or image file and use stactools to generate a stac Item, and compare the output of this stac item to a "gold" output file. What I observe is that any time the Item changes (or it could be any time it's run), the order of the stac_extensions is arbitrarily different. In this case, it means there's a significant diff to the gold files that's not related to the actual change at hand. It would be nice if the order could be consistent, for example, alphabetically sorted.

I was going to pick this one up but I am not sure that I agree that pystac should be sorting these. stac_extensions is stored as an array and in python it is a list. Both of those have an order and as far as I can tell from poking around in the code it looks like that order is being preserved. That all feels correct to me.

When creating an item the stac_extensions are appended to in the same order that extensions are added. I guess we could sort them at that point and insert into the list rather than append, but based on the OP I feel like I am missing something. Do you have a reproducer?

I'll try to get a repro case together. I've only seen it through the stactools pacakges use.

OOOh actually I just noticed this casting to set. That could be responsible for this whole thing...

https://github.com/stac-utils/pystac/blob/72564868130422f42d604950440fa83bfb8ae752/pystac/serialization/identify.py#L277-L278

Ah, yeah, that's likely it.

I was curious as to what the right way to do this and preserve order in python is, and it seems to be list(dict.fromkeys(items))

Sorry @philvarner but I am still looking for a reproducer to test my PR on.

I've tried a few times to create an isolated one, but no luck. I do see it regularly in my uses of this through stactools.

I'm going to pop this off the project since #1133 merged and we are planning to just see if that seems to fix things

Okay, I think this one's baked long enough to consider it fixed by #1133. Please re-open if it recurs.