Skip to content

Return 200 {} again for an unset displayname/avatar_url - #20200

Merged
devonh merged 5 commits into
developfrom
barodeur/fix-missing-profile-field-error
Sep 11, 2026
Merged

devonh merged 5 commits into
developfrom
barodeur/fix-missing-profile-field-error

Conversation

@barodeur

@barodeur barodeur commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Part of: #19414

When MSC4133 (custom profile fields) was implemented, the returned value for an unset display name changed from 200 {} to 200 { displayname: null }. This happened first on the unstable uk.tcpip.msc4133 path in #17488 (1.123.0), then on the stable path when #18635 (1.135.0) unified the displayname, avatar_url and custom field servlets. Neither PR discussed the change in review, so it looks like an unintended side effect of the refactor rather than a deliberate decision.

The v1.16 spec mandated to change from returning 200 {} to 404 but change was not identified as breaking and was eventually not implemented in other clients and server. This PR has a sister MSC that proposes to return to the pre-1.16 error codes: MSC4537.

Before:

GET /_matrix/client/v3/profile/@alice:test/displayname
  200 {"displayname": null}

After:

GET /_matrix/client/v3/profile/@alice:test/displayname
  200 {}

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

Since #18635, `GET /profile/{userId}/{displayname,avatar_url}` returns
`{"<field>": null}` when the field is unset, rather than the empty
object it returned before. Add a test asserting the previous behaviour.

Claude-Session: https://claude.ai/code/session_012TjugsZmHDB6Rx4pqa4hA9
`GET /profile/{userId}/{displayname,avatar_url}` returned
`{"<field>": null}` for an unset field since #18635 unified the
displayname, avatar_url and custom field servlets. Restore the previous
behaviour of returning an empty object when the field is unset.

Custom fields are unaffected: those already return a 404 when unset.

Claude-Session: https://claude.ai/code/session_012TjugsZmHDB6Rx4pqa4hA9
@barodeur
barodeur marked this pull request as ready for review September 9, 2026 08:55
@barodeur
barodeur requested a review from a team as a code owner September 9, 2026 08:55
@barodeur
barodeur requested review from devonh and removed request for a team September 9, 2026 08:55
Comment on lines +158 to +160
ret[field_name] = await self.profile_handler.get_profile_field(
user, field_name
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the generic profile field case also have the same fix applied?

@barodeur barodeur Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now, the ecosystem, is going to accept a bit of inconsistencies with HomeServers either returning 200 {} or 404.

Here get_profile_field would raise StoreError(404, "No row found") and the HS would return 404.

I'm open to also making it return 200 {} for consistency, but the spec might change in the future back to 404 for all fields, because that is probably the correct REST semantic response

The next final change I would like to make on this matter is rather changing definitely to 404 for all fields once the spec settles and clients all accepts 404 as response for unset fields.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I agree with your assessment.

It's probably worth adding a comment in with this information so future developers don't have to go digging for why the different cases treat response handling in different ways.

@devonh

devonh commented Sep 9, 2026

Copy link
Copy Markdown
Member

Other than the one question, the changes here look complete to me.

@barodeur

Copy link
Copy Markdown
Collaborator Author

👋 thanks for your review, I replied to your question

@barodeur
barodeur requested a review from devonh September 10, 2026 08:39
@devonh
devonh merged commit 3f17bd7 into develop Sep 11, 2026
47 checks passed
@devonh
devonh deleted the barodeur/fix-missing-profile-field-error branch September 11, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Profiles A-Spec-Compliance Matrix spec compliance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants