Closed dananev closed 3 months ago
Hi! Could you please provide the plain JSON needed to add unit tests for this case? It seems that ‘model_config’ was probably just forgotten in this model
Here or in the pull-request? Without aliases it's basically:
{"link":"bafkreia4linnhpphw5fughdn3wok7okklggww34txua76r6kbphuf3vsia"}
I found out another thing. Probably, ref in BlobRef shouldn't be Union[str, IpldLink]
, but only IpldLink
.
For example, this snippet returns 400:
embed = models.AppBskyEmbedExternal.Main(
external=models.AppBskyEmbedExternal.External(
description="Yet another The Room gif",
title="oh hi mark",
uri="https://giphy.com/gifs/theroom-the-room-26CaLWA2dcqz6hS4U",
thumb=BlobRef(
mime_type="image/jpeg",
size=316179,
ref="bafkreia4linnhpphw5fughdn3wok7okklggww34txua76r6kbphuf3vsia",
)
)
)
record = client.send_post(
text="https://giphy.com/gifs/theroom-the-room-26CaLWA2dcqz6hS4U",
embed=embed,
)
Exception:
atproto_client.exceptions.BadRequestError: Response(success=False, status_code=400, content=XrpcError(error='InvalidRequest', message='Invalid app.bsky.feed.post record: Record/embed/external/thumb should be a blob ref'), headers={'Date': 'Sun, 16 Jun 2024 19:32:08 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '122', 'Connection': 'keep-alive', 'X-Powered-By': 'Express', 'Access-Control-Allow-Origin': '*', 'ETag': 'W/"7a-/Nk9d44dleWoqVCOpDSZq5x1q0M"', 'Vary': 'Accept-Encoding'})
Well, the ref could be in raw and in JSON formats. Also, there is a deprecated blob type and a new one. this class tries to support everything in one
https://atproto.com/specs/data-model#blob-type
ref (link, required): CID reference to blob, with multicodec type raw. In JSON, encoded as a $link object as usual
Without aliases it's basically: {"link":"bafkreia4linnhpphw5fughdn3wok7okklggww34txua76r6kbphuf3vsia"}
that's strange because we have test for it:
and
btw $ is required
@dananev It is a sporadic case when you want to create a BlobRef
by yourself. Typically, it is returned, for example, in a firehose as raw bytes. When you call a function like upload_blob, the process goes through XRPC, which communicates using JSON. Therefore, the response will be in the $link
format. If you are trying to construct a BlobRef
to use it with XRPC (specifically with the send_post
method), you will need to create it in a JSON-compatible format.
So instead of
thumb = BlobRef(
mime_type='text/plain',
size=0,
ref='blabla',
)
you need to do
thumb = BlobRef(
mime_type='text/plain',
size=0,
ref=IpldLink(link='blabla'),
)
I fixed this kind of creation in the linked PR. Probably it could be a good idea to have methods in BlobRef
which will convert between representations. RAW and JSON.
I still can't reproduce the initial issue :( Probably you just missed $
. The key must be $link
instead of link
@dananev please try to create BlobRef
as I mentioned above using SDK from the main branch. It should work fine with send_post
method. This bug fix will be included in the next release
To install SDK from the main branch:
pip uninstall atproto
pip install git+https://github.com/MarshalX/atproto.git@main
All good now, thank you for the quick fix!
@dananev FYI https://github.com/MarshalX/atproto/pull/348
Hi! Thanks for the SDK!
I was working with it and got a tiny issue. When you try to instantiate
IpldLink
withlink
field validation fails:To fix the issue either
link
should be declared withserialization_alias
instead of plainalias
or we should addmodel_config
toIpldLink
.I can raise a small pull-request to fix the issue.
Thanks!