-
Notifications
You must be signed in to change notification settings - Fork 83
Fix: Properly traverse the object hierarchy to get the ID #1518
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
Conversation
* Update with activities * Remove comments as the function gets used recursively now --------- Co-authored-by: Konstantin Obenland <obenland@gmx.de>
|
@obenland I merged your PR (thanks for the input) and improved the |
|
ade7adc and ccd8c2a feel unrelated to the original premise of this PR, unless I'm missing something? I'm also not sure it's needed, necessarily? Is it used anywhere yet? |
|
@obenland this is to ensure that an object is always an object and not accidentally an array. It is used by every |
|
There are still places that needs to be optimized, but I think this provides a solid foundation to ensure objects. |
Does this part not do that?
Are there any instances where we don't do that? If there are, we should fix them specifically. Creating a big fallback for an eventuality, I think, would do us a disservice as it removes any confidence in data integrity in the future. Objects are not spec'd to contain other objects, only activities can be nested (according to my current understanding of things, please correct me if I'm wrong). Let's make make sure we deal with Activities as appropriate so this is not needed. |
|
This is true if you see only one level of inheritance... We currently have the tree of
The |
This is not eventually. Every Activity that comes through the inbox is an array and we need something to properly transform these, if we do not want to have array handlers as fallbacks everywhere. |
|
This code example: <?php
$test = array(
'type' => 'Announce',
'id' => 'https://example.com/test',
'object' => array(
'id' => 'https://example.com/test2',
'type' => 'Create',
'object' => array(
'id' => 'https://example.com/test3',
'type' => 'Note',
'content' => 'Hello, world!',
),
)
);
$object = \Activitypub\Activity\Activity::init_from_array( $test );
echo '<pre>';
var_dump( $object );
echo '</pre>';currently returns: object(Activitypub\Activity\Activity)#1327 (41) {
["id":protected]=>
string(24) "https://example.com/test"
["type":protected]=>
string(8) "Announce"
["object":protected]=>
object(Activitypub\Activity\Generic_Object)#1353 (3) {
["id":protected]=>
string(25) "https://example.com/test2"
["type"]=>
string(8) "Activity"
["object"]=>
array(3) {
["id"]=>
string(25) "https://example.com/test3"
["type"]=>
string(4) "Note"
["content"]=>
string(13) "Hello, world!"
}
}
}So the nested object is still an array! With the change the result is: object(Activitypub\Activity\Activity)#1332 (41) {
["id":protected]=>
string(24) "https://example.com/test"
["type":protected]=>
string(8) "Announce"
["object":protected]=>
object(Activitypub\Activity\Activity)#1358 (41) {
["id":protected]=>
string(25) "https://example.com/test2"
["type":protected]=>
string(6) "Create"
["object":protected]=>
object(Activitypub\Activity\Base_Object)#1352 (35) {
["id":protected]=>
string(25) "https://example.com/test3"
["type":protected]=>
string(4) "Note"
["attachment":protected]=>
NULL
["attributed_to":protected]=>
NULL
["audience":protected]=>
NULL
["content":protected]=>
string(13) "Hello, world!"
}
}
} |
mattwiebe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of complexity! Could we not just run a migration on our Announces instead to fix the underlying issue?
|
@mattwiebe this is always an issue! this IS the migration we always have to do, because we get data through the inbox and have to transform it. This is not a backwards compatibility thing! This is to handle Activity-JSONs properly! |
|
We use this mechanism quite often and if the result is not properly transformed, before we store it in the DB or if we do not process it properly by retrieving it from the DB, we will get issue when we strictly rely on objects: |
|
Even |
obenland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the examples, that was helpful
* tag '5.6.1': (47 commits) Release 5.6.1 (Automattic#1542) Fix: Use specified time formatting for Outbox Activities (Automattic#1537) Fix: Default value for empty `movedTo` field (Automattic#1539) Fix: Post Interactions settings (Automattic#1540) Release 5.6.0 (Automattic#1534) lover significance (Automattic#1533) Scheduler: Don't federate Deletes of unfederated posts. (Automattic#1528) Move: use `$from` for object in `Move::externally` (Automattic#1531) Fix: Properly traverse the object hierarchy to get the ID (Automattic#1518) Mentions: Standardize around only displaying username (Automattic#1510) Tests: Reduce chance of time offsets (Automattic#1527) Import: Don't federate new attachments (Automattic#1526) Importer: Format import count number. (Automattic#1525) Move: Add a Mastodon importer (Automattic#1502) Move: use `$from` for object in `Move::internally` (Automattic#1516) Fix: Do not send self-replies (Automattic#1517) Fix: Delete Undone comments instead of trashing them (Automattic#1520) Dispatcher: Adhere to passed batch size. (Automattic#1514) Add interaction settings (Automattic#1395) Fix: Set proper default, to show Welcome screen by default (Automattic#1512) ...
While debugging the Outbox-Scheduler, I realized that the
AnnounceOutbox Items had the wrong_activitypub_object_id. It was theActivityID instead of the originalObjectID of the post/comment/...This PR checks recursively for the deepest nested ID possible. This way we always have the
ObjectID which is needed to invalidate Outbox-Activities.Proposed changes:
Other information:
Testing instructions:
Before the PR, the
AnnounceActivity would use the ID of theCreateActivity instead of theObjectID of the Post.Changelog entry
Changelog Entry Details
Significance
Type
Message
Support multiple layers of nested Outbox activities when searching for the Object ID.