Invitation pages return 500 when expires_at is infinity or -infinity

Open Beginner friendly
#48 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, postgresql, python

Research direction

Read server/orcaster_server/auth/service/invitation.py and the expiry checks at server/orcaster_server/auth/router.py:222; the issue identifies all three call sites. Add the helper and unit coverage described in the acceptance criteria, then run the invitation tests and check for remaining direct expiry comparisons. Done means both PostgreSQL infinity values produce the specified responses, existing invitation cases pass, and an Unreleased changelog entry is added.

Written by the indexing model from the issue text.

Description

bug P2 server

Problem

invitations.expires_at is a timestamptz NOT NULL column with no CHECK (server/orcaster_server/auth/models.py:98), so PostgreSQL accepts 'infinity' and '-infinity'. The database driver decodes them as naive datetimes (datetime.max and datetime.min, no tzinfo). Finite values come back timezone-aware.

The expiry checks compare the value with datetime.now(UTC) in Python:

  • GET /auth/accept/{token}: server/orcaster_server/auth/router.py:222
  • invitation_state: server/orcaster_server/auth/service/invitation.py:67
  • consume_invitation (used by POST /auth/accept/{token}/join and register/complete): server/orcaster_server/auth/service/invitation.py:84

Comparing a naive and an aware datetime raises TypeError: can't compare offset-naive and offset-aware datetimes. That exception has no handler, so the invite page and both accept routes answer a plain 500.

The application always writes a finite expiry when it creates an invitation. Only a row written by hand (for example 'infinity' meaning "never expires") can hold these values.

Steps to reproduce

  1. Create an invitation, then run UPDATE invitations SET expires_at = 'infinity' WHERE id = '<id>'.
  2. Open GET /auth/accept/{token}. The response is 500.
  3. Same with '-infinity', and with POST /auth/accept/{token}/join.

Proposed change

Add one helper, for example is_expired(inv, now), in server/orcaster_server/auth/service/invitation.py. If expires_at.tzinfo is None, treat it as UTC before comparing. Naive datetime.max then never expires and naive datetime.min is always expired, which matches what the two values mean. Use the helper in the three places above.

Evaluating the expiry in SQL is an alternative. Adding a CHECK (isfinite(expires_at)) constraint is not proposed: it needs a migration on an existing table for a value the application never writes.

Acceptance criteria

  • GET /auth/accept/{token} with -infinity answers like an expired invitation, not 500.
  • GET /auth/accept/{token} with infinity answers like a live invitation, not 500.
  • POST /auth/accept/{token}/join and register/complete with -infinity answer 410 (expired). With infinity they accept. No 500.
  • A unit test of the helper covers an aware finite value, naive datetime.max, naive datetime.min, and expires_at == now.
  • No direct expires_at <= now comparison on invitations remains outside the helper.
  • No schema change. Existing tests for expired, valid and disabled-workspace invitations still pass.
  • CHANGELOG entry under Unreleased.
Dominant language
Python
Stars
0
Forks
0
Avg merge
1d 1h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AInvirion/orcaster

All issues in AInvirion/orcaster

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.