Skip to content
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

Add published field to Release #17257

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

DarkaMaul
Copy link
Contributor

@DarkaMaul DarkaMaul commented Dec 9, 2024

This PR introduces the following changes :

  • a new boolean published field to the Release model
  • a migration to update every existing releases and set their published value to be the creation time

Part of #17230

Some notes:

I dislike how I changed the default Release creation call to force the publish time to be set to a timestamp, but I did not find a better solution. This created a new quirk: every time someone wants to create a new Release, they must make sure the published field is set.

The problem boils down to not setting a value for publish at the release creation, which would either semantically mean the time is not set (the solution I chose) or use a default value (e.g., the current timestamp). When choosing the latter case, we would need a placeholder value on the Python side (e.g., published=False) and to convert this placeholder to an explicit null value ( using forcing-null-on-a-column-with-a-default )

The new implementation uses a boolean field.

@DarkaMaul DarkaMaul requested a review from a team as a code owner December 9, 2024 14:00
@DarkaMaul DarkaMaul changed the title Dm/published date Add published field to Release Dec 9, 2024
@di
Copy link
Member

di commented Dec 9, 2024

Should this follow the same pattern we have for yanking, where there are yanking events with timestamps, and we have a yanked field on the model that is a boolean instead?

@DarkaMaul
Copy link
Contributor Author

Should this follow the same pattern we have for yanking, where there are yanking events with timestamps, and we have a yanked field on the model that is a boolean instead?

I like the idea as it would also not modify how new Releases are created.

Copy link
Member

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

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

LGTM, nice work @DarkaMaul!

Given that published is currently invariant as True, this shouldn't cause any observable index changes. However, for the follow-up where we make it controllable, I think we should add some integration tests to make sure the index responses are what we expect.

Comment on lines 65 to 68
.filter(
Release.project == project,
Release.published.is_(True),
)
Copy link
Member

Choose a reason for hiding this comment

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

I am very wary of this pattern, where the default gives us all releases and we have to manually filter those that are published. I think it's inevitable that we will miss this filter somewhere and this will result in the wrong releases being returned.

I think instead we need something that behaves like https://github.com/flipbit03/sqlalchemy-easy-softdelete, which makes all queries contain this filter by default, and requires manually querying for the unpublished releases instead.

(There is some additional discussion about this in #6091 because we have the same fundamental issue with any mechanics for soft deletes as well.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great call! I've updated the PR to use an SQLAlchemy event listener and intercept SELECT statements to rewrite them with an exclusion clause.

state.is_select
and not state.is_column_load
and not state.is_relationship_load
and not state.statement.get_execution_options().get("include_staged", False)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FLAG: This is added to allow querying for the published=False query but is not used in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants