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

Fix-dev-check-always-fails #437

Merged
merged 11 commits into from
Dec 5, 2024
Merged

Conversation

GracefulLemming
Copy link
Contributor

Issue: dev-check always fails during backend checks.

Background

The primary issue is thatdev-check fails in all conditions and suggests running cargo check during backend checks. Running cargo-check as suggested finishes successfully and yields no further information. A closer look at check.sh reveals that cargo check only fails once $SQLX_OFFLINE is true, suggesting that the cause of this issue is upstream in the check script. The only upstream invocation of sqlx is in the database check phase, as shown below:

echo "Checking if SQL types are up to date..."
if $(cd types && cargo sqlx prepare --check -- -p dailp &>/dev/null); then
    echo "Generating SQL types..."
    cargo sqlx prepare -- -p dailp || exit 1
fi

Running cargo sqlx prepare -- -p dailp yields the following error:

error: failed to get package in current working directory, pass `--workspace` if running from a workspace root

Adding --workspace as suggested results in a succsessful build of the dailp library alongside a "no queries found" warning. This message on its own is insufficient in furthering a root cause analysis of the initial error.

A series of google searches relating to issues in sqlx prepare eventually led to a GitHub discussion of a similar issue. A user in this thread suggested that issues of this nature could be a result of a mismatched versions of the sqlx crate and sqlx-cli. Looking at the version info in the dailp project, shown below, this seems to be the case.

sqlx-cli: 0.7.1
sqlx (crate): 0.6.3

Solution

Updating the sqlx crate used by the dailp lib in cargo.toml fixed the issue, but required a number of configuration updates. First, sqlx 0.7 required upgrading channel in rust-toolchain.toml to use a more recent Rust version (previously using 1.72.0). Since Nixpkgs provides a maximum pinned Rust version, upgrading to the most stable Rust channel available seemed reasonable. The hash associated with rust-toolchain.toml in flake.nix also had to be updated. Second, crate dependencies in flake.lock needed to be updated via cargo update. Third, dereferences needed to be added in database_sql.rs when using functions relying on implementations of sqlx:Execute to accomodate breaking changes in the implementation of sqlx's Transaction and PoolConnection. Finally, additional Sqlx codegen checks and logging were added to check.sh to improve developer experience.

Copy link

netlify bot commented Dec 4, 2024

Deploy Preview for dailp canceled.

Name Link
🔨 Latest commit 020b047
🔍 Latest deploy log https://app.netlify.com/sites/dailp/deploys/675213b19513600008d50bc7

Copy link
Collaborator

@CharlieMcVicker CharlieMcVicker left a comment

Choose a reason for hiding this comment

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

Some questions/comments:

  1. Does this part of our commit hook need to change now? Do we still have an sqlx-data.json or is the new .sqlx folder where this data lives now?
    https://github.com/NEU-DSG/dailp-encoding/blob/main/.git-hooks/pre-commit#L9-L14
# Require sqlx data to be generated when a SQL query is modified.
if git-staged "types/queries/**.sql" && ! git-staged "sqlx-data.json"; then
    printf "\nDatabase queries changed without generating sqlx types.\nPlease run 'dev-check' or 'dev-generate-types'.\n"
    HOOKS_FAILED=1
fi
  1. Why not add that --workspace flag and keep our sqlx query type data at the root level of the project like we have been? I think I like it living in types like it would now, but I wonder why we had done it at the root in the first place.
  2. If sqlx-data.json is no longer where this data is actually stored, I'd like to see it deleted as part of the PR. I'm interested what will happen if you delete it and run this script.

I'm so exciting that you've found a fix for this and we can get moving on other stuff!

@@ -1,5 +1,5 @@
[toolchain]
channel = "1.72.0"
channel = "stable"
profile = "minimal"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This scares me a little bit. Do we want this to bump without us explicitly changing anything?

Copy link
Collaborator

@CharlieMcVicker CharlieMcVicker left a comment

Choose a reason for hiding this comment

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

Just what we talked about! ᎣᏍᏛ ᎡᎵᏍᏗ

ᏩᏙ.

@GracefulLemming GracefulLemming merged commit 10b4dcd into main Dec 5, 2024
5 checks passed
@GracefulLemming GracefulLemming deleted the fix-dev-check-always-fails branch December 5, 2024 20:59
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