ATProtoKit icon indicating copy to clipboard operation
ATProtoKit copied to clipboard

[Bug]: Need to switch out BlobContainer for UploadBlobOutput

Open anna-germ opened this issue 9 months ago • 1 comments

Summary

Looks like we no longer receive an extra "blob" key indirection when fetching records, meaning using BlobContainer (instead of the preferred UploadBlobOutput) breaks parsing. It works fine if you replace BlobContainer with UploadBlobOutput, at least in AppBskyLexicon.Actor.ProfileRecord.

Reproduction Steps

Primarily from this code block -- getting the "app.bsky.actor.profile" record and attempting to parse it as an AppBskyLexicon.Actor.ProfileRecord.

let resp = try await ATProtoKit().getRepositoryRecord(
  from: did, 
  collection: AppBskyLexicon.Actor.ProfileRecord.type, 
  recordKey: "self"
)

guard let profileRecord = resp.value?.getRecord(ofType: AppBskyLexicon.Actor.ProfileRecord.self)
else {
  // throw
}

Expected Results

Expected the "app.bsky.actor.profile" record to parse correctly as an AppBskyLexicon.Actor.ProfileRecord type.

Actual Results

When parsing the "app.bsky.actor.profile" record value, the current implementation of AppBskyLexicon.Actor.ProfileRecord throws an error, due to the assumption that the avatar key has a blob key within it, when in fact avatar just maps directly to an UploadBlobOutput.

error loading profile keyNotFound(CodingKeys(stringValue: "blob", intValue: nil), 
Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "value", intValue: nil), 
CodingKeys(stringValue: "avatar", intValue: nil)], debugDescription: "No value associated with key 
CodingKeys(stringValue: \"blob\", intValue: nil) (\"blob\").", underlyingError: nil))

What operating systems did you experience this bug?

iOS/iPadOS

Operating System Version

iOS 18.2

ATProtoKit Version

0.25.3

Additional Context

Within AppBskyLexicon.Actor.ProfileRecord, we just need to update avatarBlob and bannerBlob to have type ComAtprotoLexicon.Repository.UploadBlobOutput? instead of ComAtprotoLexicon.Repository.BlobContainer?.

I can check if BlobContainer can be replaced everywhere or if it's just AppBskyLexicon.Actor.ProfileRecord, once y'all approve this bug to warrant a PR! And it seems this bug is good news, given your note on the BlobContainer struct...

// MARK: -
// TODO: Find a way to remove BlobContainer without breaking the JSON encoding.
// This will be here until a way to remove this without the issues of
// the JSON encoding are solved.

anna-germ avatar Mar 20 '25 20:03 anna-germ

Yes, I want to get rid of BlobContainer entirely. I haven't gotten around to completely investigate how to get that to happen yet as I'm working on so many other things, but this is something I've been wanting to do for some time, especially since I'm working on the lexicon generator and it needs to map out everything perfectly.

If you're able to fix it, however, I would be very happy to accept the PR.

MasterJ93 avatar Mar 21 '25 03:03 MasterJ93