Skip to content

chore: vendor hasql - #5084

Merged
wolfgangwalther merged 1391 commits into
PostgREST:mainfrom
wolfgangwalther:vendor-hasql
Aug 20, 2026
Merged

wolfgangwalther merged 1391 commits into
PostgREST:mainfrom
wolfgangwalther:vendor-hasql

Conversation

@wolfgangwalther

@wolfgangwalther wolfgangwalther commented Jul 8, 2026

Copy link
Copy Markdown
Member

Step 2 for #4823. This replaces the hasql-* dependencies (which includes hasql-notifications, but I don't know of a way not to fork that as well, since it depends on hasql itself) with a vendored copy keeping the original history.

We're only using the source code, so far, but not the original tests. That will be a next, separate step to merge these tests with ours and integrate them into the nix tooling etc.

Right now, it builds. Let's see what CI says - I assume it should also pass all our tests.

TODO:

  • Seems like I should use hasql-pool 1.3.0.3 instead of 1.3.0.4
  • Fix doctests properly

Depends on #5093 and #5094.

nikita-volkov and others added 30 commits April 25, 2024 10:00
As a workaround for Hackage including the dependencies of internal libs in the public list of package dependencies.
* clean-up-public-deps:
  Remove rerebase from the internal library deps
Report errors when LISTEN or UNLISTEN fail
Remove stack from repo since I am currently working only with cabal
@wolfgangwalther

Copy link
Copy Markdown
Member Author

(let's only discuss the MIT-copyright case here, since Diogo already agreed to contribute hasql-notifications via MIT license anyway)

We can state in our license file:

Sure, this is what this PR is doing essentially. Maybe in different words, but it's the same.

The whole discussion is about Steve not wanting to change that LICENSE file. And then it becomes a problem.

You can not do the following:

  • Have the top-level LICENSE file as-is.
  • Have the vendored code in vendor/hasql/...
  • Have the copyright notice in vendor/hasql/LICENSE
  • Move code from vendor/hasql to src/

In this case you are violating copyright, because clearly you imply that the copyright in vendor/hasql/LICENSE only applies to the files below that.

It gets worse, though: Even if you argue "yeah, but technically it doesn't say where to reproduce the copyright", you will suddenly have code in src/ that needs to carry the copyright from vendor/hasql/LICENSE when copied somewhere else.

Now someone who consumes the PostgREST repository comes along, takes code from src/ and complies with the top-level LICENSE by taking the copyright notice from there along. Now they are violating the vendored copyrights, but unknowingly. This is the thing that we absolutely must prevent.

This means that the copyright notices for the vendored code and our PostgREST code must be in the same place, as you already pointed out.

@mkleczek

Copy link
Copy Markdown
Collaborator

(let's only discuss the MIT-copyright case here, since Diogo already agreed to contribute hasql-notifications via MIT license anyway)

We can state in our license file:

Sure, this is what this PR is doing essentially. Maybe in different words, but it's the same.

The whole discussion is about Steve not wanting to change that LICENSE file. And then it becomes a problem.

But it can be a different top level file - wouldn't that solve the issue? (I am not really sure if we are not talking past each other really).

You can not do the following:

  • Have the top-level LICENSE file as-is.
  • Have the vendored code in vendor/hasql/...
  • Have the copyright notice in vendor/hasql/LICENSE
  • Move code from vendor/hasql to src/

In this case you are violating copyright, because clearly you imply that the copyright in vendor/hasql/LICENSE only applies to the files below that.

I don't think it implies that but I agree it might look like that.

The whole point is that we don't have to be specific when saying "PostgREST includes large portion of hasql" and include required copyright notice somewhere. It does not matter where - the only thing that matters is that it is included both in source and binary distributions (and in the repository).

MIT license is not file based: you can copy/paste parts of the licensed code into your own code and it is fine as long as you include required copyright notice somewhere. It is in contrast to eg. MPL, which is file scoped.

Now someone who consumes the PostgREST repository comes along, takes code from src/ and complies with the top-level LICENSE by taking the copyright notice from there along. Now they are violating the vendored copyrights, but unknowingly. This is the thing that we absolutely must prevent.

It is easy: just state somewhere clearly that PostgREST includes third-party libraries and what their license terms are. It is on users to familiarize themselves with license terms of all the software they use in their derivative works - not on us.

This means that the copyright notices for the vendored code and our PostgREST code must be in the same place, as you already pointed out.

Looks like indeed - that might be the easiest thing to do: maintain a file with a list of dependencies, their copyright notices and possibly links to their licenses.

@wolfgangwalther

Copy link
Copy Markdown
Member Author

Both @diogob and @nikita-volkov have agreed via email to contribute the code we're vendoring here to the PostgREST project under the MIT license with the current "The PostgREST contributors" copyright. Thank you a ton, both of you - this makes it much easier for us! 🚀 ❤️

The relevant commit is 6702809, which removes the vendored licenses and thus makes the top-level license take effect. Would appreciate an approval from both of you for public transparency. Your approval will only be counted as "OK with the license/copyright change", not necessarily as an approval of forking/vendoring in general.

We'll technically also need an approval from @laurenceisla, who contributed diogob/hasql-notifications@962ae98 to hasql-notifications under the BSD-3 license, which would now be under the MIT license here.

@wolfgangwalther
wolfgangwalther dismissed steve-chavez’s stale review August 16, 2026 10:48

The LICENSE file is now unchanged.

@laurenceisla laurenceisla left a comment

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.

We'll technically also need an approval from @laurenceisla

Approving as stated above 👍

@nikita-volkov

Copy link
Copy Markdown
Contributor

I approve this change.

You have my permission to merge the copyright notice into "The PostgREST contributors", with the git history preserving my authorship.

This approval is strictly for the copyright adjustment. It is not an endorsement of the vendoring decision. The PostgREST team assumes full responsibility for the maintenance of this forked version.

@diogob diogob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I approve this change.

@mkleczek

Copy link
Copy Markdown
Collaborator
  • Seems like I should use hasql-pool 1.3.0.3 instead of 1.3.0.4

https://github.com/nikita-volkov/hasql-pool/tree/v1.3.0.5 contains an important fix to pool capacity handling.

BTW. How are we going to handle upstream fixes? Do they need to be ported manually?

Secondly - sorry for late chipping in here, but putting all separate libraries into a single source tree blurs API boundaries between them and is anti-modular. (I am not sure if it also makes backporting of upstream changes difficult).

This removes everything from the vendored hasql packages, except their
license, source code, tests and .cabal file.

We also remove metadata which is not needed anymore from .cabal file,
but leave everything that needs to be ported to our own .cabal file
later in place.
Both Nikita (hasql, hasql-pool, hasql-dynamic-statements,
hasql-implicits) and Diogo (hasql-notifications) have agreed to
contribute these projects at the respective version to the PostgREST
project under the MIT license and under the "The PostgREST contributors"
copyright our license has.

This makes it significantly easier for us to ensure we're complying with
their copyright and our downstream users will, too.

A big thank you to both of them.
To run it, we need to remove the Arrows extension from postgrest.cabal.
It doesn't seem to be depended upon by the hasql code (but was still
introduced along with it), but breaks the style check. That's because
stylish-haskell applies all extensions found in the .cabal file for all
files, even when they are only part of *one* component. The Arrows
extension makes `proc` a reserved keyword, which is used in CallPlan.hs.
I did not fix all of these by hand, but used the `--refactor` flag on
hlint to do it for me. This is something that we might want to add in
the future by default.
@wolfgangwalther
wolfgangwalther merged commit 5aca0a3 into PostgREST:main Aug 20, 2026
25 of 27 checks passed
@wolfgangwalther

wolfgangwalther commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

Just rebased to be able to merge fast-forward, no changes.

Edit: Sorry, @mkleczek, did not read your comment until after the merge. Will respond to it later.

@wolfgangwalther
wolfgangwalther deleted the vendor-hasql branch August 20, 2026 05:33
@wolfgangwalther

Copy link
Copy Markdown
Member Author

https://github.com/nikita-volkov/hasql-pool/tree/v1.3.0.5 contains an important fix to pool capacity handling.

IIRC, this was in a code path that we do not use, correct? This would be code that would be removed in the next step anyway - we don't need to keep our vendored version of hasql generally useful, we can restrict it to the code we are actually using to reduce maintenance effort.

BTW. How are we going to handle upstream fixes? Do they need to be ported manually?

It depends on what you mean by "ported". You probably can not just take them as is, and try to apply them here, because:
a) You would have to ask Nikita for agreement to contribute this under our copyright in each instance.
b) You'd possibly be violating our AI policy, because the code could be generated with LLMs.

So essentially, you'd have to acknowledge the problem and then write your own fix (ideally without looking at the upstream change!).

Secondly - sorry for late chipping in here, but putting all separate libraries into a single source tree blurs API boundaries between them and is anti-modular. (I am not sure if it also makes backporting of upstream changes difficult).

The latter is not important, because see above. Also backporting will already not work well, because we apply our own formatters and linters - cherry-picks will quickly not apply anymore anyway! The idea is to reduce the code to the minimum code we use - which means we are using everything in that codebase. IMHO, the biggest benefit of having the hasql code modular is, that the user can pick which parts of the library they want to use and which they don't need. This is a non-issue for us, because everything that we have in here is used.

@mkleczek

Copy link
Copy Markdown
Collaborator

https://github.com/nikita-volkov/hasql-pool/tree/v1.3.0.5 contains an important fix to pool capacity handling.

IIRC, this was in a code path that we do not use, correct?

At the moment -yes. But let's not hand-wave away the problem of maintenance and bugfixes backporting.

This would be code that would be removed in the next step anyway - we don't need to keep our vendored version of hasql generally useful, we can restrict it to the code we are actually using to reduce maintenance effort.

I wouldn't remove this code because it is useful and potentially very relevant to us (ie. running some SQL initializing each new session - setting up caches, session variables, temporary tables etc. - all of this was already discussed in other threads).
Removal means we would need to re-implement it by ourselves once we need that.
Leaving it unpatched means that we have to remember to fix it once we start using it.

BTW. How are we going to handle upstream fixes? Do they need to be ported manually?

It depends on what you mean by "ported". You probably can not just take them as is, and try to apply them here, because: a) You would have to ask Nikita for agreement to contribute this under our copyright in each instance. b) You'd possibly be violating our AI policy, because the code could be generated with LLMs.

So essentially, you'd have to acknowledge the problem and then write your own fix (ideally without looking at the upstream change!).

That is going to cost us a lot in terms of effort and - what's worse - quality, I'm afraid.

IMHO, the biggest benefit of having the hasql code modular is, that the user can pick which parts of the library they want to use and which they don't need. This is a non-issue for us, because everything that we have in here is used.

It sounds like you are saying "modularity is not needed if you are not publishing modules separately" - which is clearly backwards. Modularity is needed to keep software maintainable - does not matter if modules are public or private.

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

Labels

hasql Related to the hasql library

Development

Successfully merging this pull request may close these issues.