Get commit_id when Speckle 2.0 has model_id?

Hi, quick question.

Old models have in their URL a commit_id included such that the wrapper extracts the commit_id and we can call:

commit_obj = client.commit.get(wrapper.stream_id, wrapper.commit_id)

For Speckle v2, I only get model_id, but the commit_id is empty.

commit_obj = client.commit.get(wrapper.stream_id, wrapper.model_id)

does not give the Base object. Where is the error in my thinking? Do I have the wrong URL or do I have to use a different function?

Thank you in advance!!

Hey @janix ,

As you might know, Commits have been renamed to Versions in the new frontend.
They are a bit trickier to find: simply expand the model history, and click on a version. Its commitId will be appended to the URL after the @.

I’m not familiar with the Python SDK and I’m not sure if the wrapper already supports the new URL structure, but @gjedlicska and @Kateryna should know :slight_smile:

Apologies if everything has not been properly updated & documented yet, we’re in the process of doing so!

As @teocomi says, not all the underlying SDKs have fully implemented both terminology sets yet.

Consequently, depending on how full a URL you pass to the StreamWrapper, you will indeed get different results between the new URL schema (projects and models) and the legacy (streams and branches)

If you directly address a version in the new schema, as per Teo’s screenshot, this will be signified with an @, and StreamWrapper will return this as a commit_idyes, backwards compatibility has a cognitive load

https://app.speckle.systems/projects/395d60e295/models/c25813b37a@2cd9521ac3

wrapper.commit_id => 2cd9521ac3

If instead, you are only passing the bare URL of a model: e.g. https://app.speckle.systems/projects/395d60e295/models/c25813b37a

You will need to retrieve the versions such that:

# Initialise StreamWrapper and retrieve model and commit IDs
wrapper = StreamWrapper(
    "https://app.speckle.systems/projects/395d60e295/models/c25813b37a")
commit_id = wrapper.commit_id

# Fetch commit and create a transport for operations
if commit_id is None:
    stream = client.stream.get(wrapper.stream_id)
    model = next((branch for branch in stream.branches.items
                  if branch.id == wrapper.model_id), None)
    commit = model.commits.items[0] if model else None

transport = ServerTransport(client=client, stream_id=wrapper.stream_id)

# Retrieve and process the referenced object if commit is available
commit_data = (operations.receive(obj_id=commit.referencedObject,
                 remote_transport=transport) if commit else None)
3 Likes

Late repsonse, but your code fixed the problem. Thanks!!

1 Like