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

Sort hashes of signature fields and save branch hash back to DB if the DB hash is incorrect #4769

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

ogenstad
Copy link
Contributor

@ogenstad ogenstad commented Oct 29, 2024

While troubleshooting #4682 I realized that there was something wrong with how branches are created and in my database any branch that I created would have a different schema hash compared to "main". This leads to a situation where we always download a new branch from the database.

The call to update the hash of a branch here:
https://github.com/opsmill/infrahub/blob/infrahub-v0.16.4/backend/infrahub/graphql/mutations/branch.py#L89

Will (depending on schema) produce a different hash than the main branch.

There might be others but I tracked this problem down to _get_signature_field() where it looks like we've thought about this before where we order the values. It might be that we now have list of lists and only sort by the outer list.

nodes:
  - name: BackBoneService
    namespace: Infra
    description: "Backbone Service"
    label: "Backbone Service"
    icon: "carbon:container-services"
    inherit_from:
      - InfraService
    uniqueness_constraints:
      - ["circuit_id__value", "internal_circuit_id__value"]

I.e in this example we'd sort the uniqueness_constraints list but not the content so we could get different load orders:

["circuit_id__value", "internal_circuit_id__value"]

vs.

["internal_circuit_id__value", "circuit_id__value"]

I haven't dug deep into this so the last part is just me guessing.

Another problem that can occur is when we restart Infrahub, and pull the branch information from the database then we have a function that checks if the hash coming from the database is valid or not, if the DB hash is invalid we log a warning and just proceed instead of saving back the hash to the database. This often leads to us being in a situation where the schema hash differs between branches which is especially problematic when we create a new branch and the logic to populate the registry thinks that it needs to load all of the schema from the database instead of using the local cache.

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Oct 29, 2024
@dgarros dgarros added the type/bug Something isn't working as expected label Oct 29, 2024
@ogenstad ogenstad changed the title Sort hashes of signature fields Sort hashes of signature fields and save branch hash back to DB if the DB hash is incorrect Oct 29, 2024
@ogenstad ogenstad marked this pull request as ready for review October 29, 2024 16:24
@ogenstad ogenstad requested a review from a team October 29, 2024 16:24
@ogenstad ogenstad merged commit 385513e into release-1.0 Oct 30, 2024
31 checks passed
@ogenstad ogenstad deleted the pog-sort-hashes branch October 30, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants