Skip to content

Attachment content IDs are cast to 0 during hydration #20

Description

@virtualLast

Description

After introducing the additional hydration for attachments (see #18 ), I have noted that Confluence Cloud returns attachment content IDs as prefixed strings, for example:

{
    "id": "att884637698",
    "type": "attachment"
}

However, AbstractContent::load() currently casts all content IDs to integers:

$content->setId((int) $data['id']);

and AbstractContent::$id is typed as ?int.

As a result, attachment IDs such as:

att884637698

are hydrated as:

0
Example

A request to:

GET /content/{pageId}/child/attachment

returns an attachment payload containing:

{
"id": "att884637698",
"type": "attachment",
"title": "example.jpg",
"_links": {
"self": "https://example.atlassian.net/wiki/rest/api/content/att884637698"
}
}

After hydration:

$attachment->getId();

returns:

0
Expected behaviour

The original attachment ID should be preserved:

$attachment->getId() === 'att884637698';

Possible fix

Widen the content ID type from int to int|string:

private int|string|null $id = null;

public function getId(): int|string|null
{
    return $this->id;
}

public function setId(int|string $id): self
{
    $this->id = $id;

    return $this;
}

Then hydrate the ID without casting:

$content->setId($data['id']);
This would preserve existing numeric page IDs while also supporting string attachment IDs.

I'm happy to knock out a PR for the above - just let me know if you're happy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions