Skip to content

Commit

Permalink
Merge pull request #1081 from digitallyinduced/fix-query-or
Browse files Browse the repository at this point in the history
Fixed queryOr causing strange type errors in complex Queries.
  • Loading branch information
mpscholten authored Sep 4, 2021
2 parents 359be70 + bfe64e6 commit ea6bcf7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions IHP/QueryBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,8 @@ queryUnion firstQueryBuilderProvider secondQueryBuilderProvider = NoJoinQueryBui
-- > (filterWhere (#public, True))
-- > |> fetch
-- > -- SELECT * FROM pages WHERE created_by = '..' OR public = True
queryOr :: (HasQueryBuilder queryBuilderProvider joinRegister, HasQueryBuilder queryBUilderProvider'' joinRegister'', HasQueryBuilder queryBuilderProvider''' joinRegister''') => (queryBuilderProvider model -> queryBuilderProvider''' model) -> (queryBuilderProvider model -> queryBUilderProvider'' model) -> queryBuilderProvider model -> NoJoinQueryBuilderWrapper model
queryOr firstQuery secondQuery queryBuilder = NoJoinQueryBuilderWrapper
queryOr :: (HasQueryBuilder queryBuilderProvider joinRegister, HasQueryBuilder queryBuilderProvider'' joinRegister'', HasQueryBuilder queryBuilderProvider''' joinRegister''') => (queryBuilderProvider model -> queryBuilderProvider''' model) -> (queryBuilderProvider model -> queryBuilderProvider'' model) -> queryBuilderProvider model -> queryBuilderProvider model
queryOr firstQuery secondQuery queryBuilder = injectQueryBuilder
(UnionQueryBuilder {
firstQueryBuilder = getQueryBuilder $ firstQuery queryBuilder,
secondQueryBuilder = getQueryBuilder $ secondQuery queryBuilder}
Expand Down

10 comments on commit ea6bcf7

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @mpscholten!

Following the direction here:

https://ihp.digitallyinduced.com/Guide/updating.html#updating-to-a-specific-git-commit

I updated default.nix with the following:

    ihp = builtins.fetchGit {
        url = "https://github.com/digitallyinduced/ihp.git";
        rev = "ea6bcf73c93dd5a1f3440e39c877ec7da16dc43b";
        ref = "*";
    };

Rebuilt:

nix-shell -j auto --cores 0 --run 'make -B .envrc'

When I access a page that was working before the update, I get this:

Server started
Nothing
libpq: failed (could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/home/dharmatech/Dropbox/Documents/ContosoUniversityIhp/build/db/.s.PGSQL.5432"?
)
GET /Instructors
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
  Status: 500 Internal Server Error 0.0009581s

Let me know if there's anything you want me to test on this end.

Thanks for looking into this!

@mpscholten
Copy link
Member Author

Choose a reason for hiding this comment

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

Can you run the dev server in debug mode and share logs?

DEBUG=1 ./start

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

Ran as follows:

$ DEBUG=1 ./start > /tmp/ihp-debug.txt

Contents of ihp-debug.txt:

IHP Version: 0.14.0
 ===> AppState {postgresState = NotStarted, appGHCIState = NotStarted, statusServerState = NotStarted, liveReloadNotificationServerState = NotStarted, fileWatcherState = NotStarted, toolServerState = NotStarted}
UpdateToolServerState Started
 ===> AppState {postgresState = NotStarted, appGHCIState = NotStarted, statusServerState = NotStarted, liveReloadNotificationServerState = NotStarted, fileWatcherState = NotStarted, toolServerState = Started}
UpdateStatusServerState Started
 ===> AppState {postgresState = NotStarted, appGHCIState = NotStarted, statusServerState = Started, liveReloadNotificationServerState = NotStarted, fileWatcherState = NotStarted, toolServerState = Started}
UpdateLiveReloadNotificationServerState Started
 ===> AppState {postgresState = NotStarted, appGHCIState = NotStarted, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = NotStarted, toolServerState = Started}
UpdatePostgresState Started
 ===> AppState {postgresState = Started, appGHCIState = NotStarted, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = NotStarted, toolServerState = Started}
UpdateFileWatcherState Started
 ===> AppState {postgresState = Started, appGHCIState = NotStarted, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
[("ihpVersion","0.14.0"),("os","linux (WSL)"),("arch","x86_64"),("projectId","4990863565814618c4c98af5485d98c7649a2bbc0fb8bcb84955469570cb1aa61b76d4d03a3d6e25193ae55fc072735bdaf14cc3b33369d4f1de6828d161e5a0")]
GHCI: :script build/ihp-lib//applicationGhciConfig
GHCI: :set prompt ""
GHCI: import qualified ClassyPrelude
GHCI: :l Main.hs
UpdateAppGHCIState Loading
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "package flags have changed, resetting and loading new packages..."}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "Loaded GHCi configuration from .ghci"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "\ESC[38;5;208m\STXIHP>\ESC[m\STX package flags have changed, resetting and loading new packages..."}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "\ESC[38;5;208m\STXIHP>\ESC[m\STX [ 1 of 23] Compiling Application.Helper.Controller ( Application/Helper/Controller.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 2 of 23] Compiling Application.Helper.View ( Application/Helper/View.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 3 of 23] Compiling Config           ( Config/Config.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 4 of 23] Compiling Generated.Types  ( build/Generated/Types.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
IHP Telemetry is activated. This can be disabled by setting env variable IHP_TELEMETRY_DISABLED=1
ReceiveAppOutput {line = StandardOutput "[ 5 of 23] Compiling Web.Types        ( Web/Types.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
�[36mGET�[0m /
�[37m  Accept: �[0mtext/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
�[37m  Status: �[0m�[32m200 OK�[0m 0.0018779s

ReceiveAppOutput {line = StandardOutput "[ 6 of 23] Compiling Web.Routes       ( Web/Routes.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 7 of 23] Compiling Web.Controller.Prelude ( Web/Controller/Prelude.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 8 of 23] Compiling Web.View.Layout  ( Web/View/Layout.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[ 9 of 23] Compiling Web.View.Prelude ( Web/View/Prelude.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[10 of 23] Compiling Web.View.Instructors.Show ( Web/View/Instructors/Show.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[11 of 23] Compiling Web.View.Instructors.New ( Web/View/Instructors/New.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[12 of 23] Compiling Web.View.Instructors.Index ( Web/View/Instructors/Index.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[13 of 23] Compiling Web.View.Instructors.Edit ( Web/View/Instructors/Edit.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[14 of 23] Compiling Web.Controller.Instructors ( Web/Controller/Instructors.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[15 of 23] Compiling Web.View.Static.Welcome ( Web/View/Static/Welcome.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[16 of 23] Compiling Web.Controller.Static ( Web/Controller/Static.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[17 of 23] Compiling Web.View.Students.Edit ( Web/View/Students/Edit.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[18 of 23] Compiling Web.View.Students.Index ( Web/View/Students/Index.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[19 of 23] Compiling Web.View.Students.New ( Web/View/Students/New.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[20 of 23] Compiling Web.View.Students.Show ( Web/View/Students/Show.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[21 of 23] Compiling Web.Controller.Students ( Web/Controller/Students.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[22 of 23] Compiling Web.FrontController ( Web/FrontController.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "[23 of 23] Compiling Main             ( Main.hs, interpreted )"}
 ===> AppState {postgresState = Started, appGHCIState = Loading, statusServerState = Started, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
AppModulesLoaded {success = True}
GHCI: app <- ClassyPrelude.async (main `catch` \(e :: SomeException) -> IHP.Prelude.putStrLn (tshow e))
 ===> AppState {postgresState = Started, appGHCIState = Loaded, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
AppStarted
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
�[36mGET�[0m /ihp-icon.svg
�[37m  Accept: �[0mimage/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
�[37m  Status: �[0m�[31m404 Not Found�[0m 0.000141s

�[36mGET�[0m /ihp-icon-white-bg.svg
�[37m  Accept: �[0mimage/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
�[37m  Status: �[0m�[31m404 Not Found�[0m 0.0002353s

�[36mGET�[0m /ShowTable
�[37m  Params: �[0m[("tableName","instructors")]
�[37m  Accept: �[0mtext/html, application/xhtml+xml
�[37m  Status: �[0m�[32m200 OK�[0m 0.0011066s

�[36mGET�[0m /ShowTable
�[37m  Params: �[0m[("tableName","students")]
�[37m  Accept: �[0mtext/html, application/xhtml+xml
�[37m  Status: �[0m�[32m200 OK�[0m 0.0015013s

ReceiveAppOutput {line = ErrorOutput "Nothing"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = ErrorOutput "libpq: failed (could not connect to server: No such file or directory"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = ErrorOutput "\tIs the server running locally and accepting"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = ErrorOutput "\tconnections on Unix domain socket \"/home/dharmatech/Dropbox/Documents/ContosoUniversityIhp/build/db/.s.PGSQL.5432\"?"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = ErrorOutput ")"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "\ESC[36mGET\ESC[0m /Instructors"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "\ESC[37m  Accept: \ESC[0mtext/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput "\ESC[37m  Status: \ESC[0m\ESC[35m500 Internal Server Error\ESC[0m 0.0007573s"}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
ReceiveAppOutput {line = StandardOutput ""}
 ===> AppState {postgresState = Started, appGHCIState = Running, statusServerState = Paused, liveReloadNotificationServerState = Started, fileWatcherState = Started, toolServerState = Started}
Stop called
StatusServer: Cannot stop as not running

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

And just to confirm, when I reverted default.nix and rebuilt, the page loaded fine.

Switched back to the new commit and the issue returned.

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

@mpscholten,

In case it helps, here's the repository and branch that the issue occurs in:

https://github.com/dharmatech/ContosoUniversityIhp/tree/2021-09-04-02-queryOr-fix

This is a conversion of a very small subset of the following ASP.NET Core tutorial just to test out various parts of IHP:

https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/intro?view=aspnetcore-5.0&tabs=visual-studio

@mpscholten
Copy link
Member Author

Choose a reason for hiding this comment

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

Logs look ok.

What is the output on http://localhost:8001/PostgresLogs ?

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, this makes it clear :-)

2021-09-04 02:49:44.155 PDT [1596] FATAL:  database files are incompatible with server
2021-09-04 02:49:44.155 PDT [1596] DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.3.

@mpscholten
Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense 👍 I just checked the repo and your master is on IHP v0.12. We've updated the nixpkgs version with IHP v0.13, which also included an upgrade of the postgres version :) You can run make clean to get rid of the current database state. Then run nix-shell and make -B .envrc after that.

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll give that a whirl!

I wonder if the directions here should perhaps mention make clean to handle this situation?

https://ihp.digitallyinduced.com/Guide/updating.html#updating-to-a-specific-git-commit

@dharmatech
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I did make clean followed by nix-shell and make -B .envrc inside there, then exited the nix-shell.

I got a different error message, but it was just saying to push 'Update DB'. I did so and the page is working now. :-)

Thanks so much Marc!

Please sign in to comment.