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

Remove inappropriate SafeToInsert constraints #73

Merged
merged 2 commits into from
Dec 13, 2023
Merged

Conversation

chris-martin
Copy link
Contributor

@chris-martin chris-martin commented Dec 13, 2023

Persistent 2.14 introduced the SafeToInsert class to flag a record as being usable with the insert; is a record is not "safe to insert" then it must be inserted with insertKey.

#66 introduced a compatibility class GraphulaSafeToInsert to allow graphula to be usable with persistent >=2.14. However, it did so by placing excessive GraphulaSafeToInsert constraints.

  • For node (which handles cases where the record's key source is SourceDefault or SourceArbitrary) this is somewhat overconstrained; SafeToInsert should be necessary when the record's key source is SourceDefault, but it should not be necessary when the key is SourceArbitrary, since we will always be generating a key to use for the insert.
  • For nodeKeyed, the SafeToInsert constraint should not be needed at all, since a key has been provided.

This PR fixes those constraints, though it isn't easy to see because some of it is buried under a handful of type-level functions. (I acknowledge that this implementation could probably be made prettier, though it's "good enough for now" IMO.)

MonadGraphulaFrontend now needs a new insertKeyed function in addition to insert, because insertions with and without a key now require different calls to Persistent. This is the cause for the major version bump, as it will be a breaking change for any instances of the class.

Upgrading to this version of graphula (and adding SafeToInsert constraints to a handful of functions) is necessary and sufficient for upgrading megarepo/backend to the latest persistent.

Copy link
Member

@pbrisbin pbrisbin left a comment

Choose a reason for hiding this comment

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

The type family stuff is a bit over my head, but I'm glad to see this solved.

I think the main open question causing #70 to stall was if introducing insertKeyed could be done without a major version bump. Seems like you're saying it cannot, but let's do it anyway. I tend to agree.

Comment on lines +27 to +32
, KeySourceTypeM
, KeyForInsert
, KeyRequirementForInsert
, InsertWithPossiblyRequiredKey (..)
, Required (..)
, Optional (..)
Copy link
Member

Choose a reason for hiding this comment

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

Do users bump into this stuff at all, or is it all encapsulated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only concern is it might show up in type errors, not sure. Otherwise no.

@chris-martin chris-martin merged commit 7478a69 into main Dec 13, 2023
10 checks passed
@chris-martin chris-martin deleted the safe-to-insert branch December 13, 2023 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants