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

Resolve issues related to multiple global attributes instances showing in the ZAP UI #1006

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

brdandu
Copy link
Collaborator

@brdandu brdandu commented Apr 25, 2023

  • This happens when the matter/zigbee sdks are updated and the same .zap sample app file is opened using zap.
  • Updating the attribute tables constraints such that attributes are unique based on cluster_ref, package_ref, code, mfg code and side
  • Added CLUSTER_REF_NOT_NULL and MANUFACTURER_CODE_NOT_NULL to the table because the unique constraint does not work correctly with null values in sqlite. Therefore adding an empty string to them and using those in the unique constraint
  • In query-loader#INSERT_ATTRIBUTE_QUERY using ignore such that duplicate attribute insertions are ignored.
  • In query-impexp#importAttributeForEndpointType ignoring insert if an endpoint type attribute already exists based on UNIQUE(ENDPOINT_TYPE_REF, ATTRIBUTE_REF, ENDPOINT_TYPE_CLUSTER_REF ). The ZAP UI was running into this when SDK was updated and the saved sample .zap file was opened again.
  • JIRA: ZAPP-1079

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2023

Codecov Report

Merging #1006 (475e6f5) into master (1e8c08c) will increase coverage by 0.01%.
The diff coverage is 80.64%.

❗ Current head 475e6f5 differs from pull request most recent head 7e204ae. Consider uploading reports for the commit 7e204ae to get more accurate results

@@            Coverage Diff             @@
##           master    #1006      +/-   ##
==========================================
+ Coverage   67.06%   67.07%   +0.01%     
==========================================
  Files         157      157              
  Lines       17187    17211      +24     
  Branches     3753     3755       +2     
==========================================
+ Hits        11527    11545      +18     
- Misses       5660     5666       +6     
Impacted Files Coverage Δ
src-electron/db/query-package.js 90.14% <33.33%> (-0.86%) ⬇️
src-electron/zcl/zcl-loader-silabs.js 94.37% <85.18%> (-0.35%) ⬇️
src-electron/db/db-api.js 79.84% <100.00%> (+0.07%) ⬆️

@brdandu brdandu force-pushed the bug/removeDuplicateEntriesFromAttributeTables/ZAPP-1079 branch from d137b3e to 475e6f5 Compare May 5, 2023 15:25
…g in the ZAP UI and resolving issues related to .zap repo deletion

- This happens when the matter/zigbee sdks are updated and the same .zap sample app file is opened using zap.
- Updating the attribute tables constraints such that attributes are unique based on cluster_ref, package_ref, code, mfg code and side
-  Added CLUSTER_REF_NOT_NULL and MANUFACTURER_CODE_NOT_NULL to the table because the unique constraint does not work correctly with null values in sqlite. Therefore adding an empty string to them and using those in the unique constraint
-  The ZAP UI was running into this when SDK was updated and the saved sample .zap file was opened again.
- In db-api, setting PRAGMA FOREIGN_KEYS=1 because each instance of the db needs to have this for on delete cascades to work properly
- Removing the IGNORE commands from the insert commands for attribute and endpoint_type_attribute tables because ignore just hides the underlying issue of attempting to insert duplicate entries into the database
- Adding the query-package#deletePackagesByPackageId to delete package by id and also follow up additional deletions across all the tables with the on delete cascade operation
- Updating the schema with on delete cascade
- In zcl-loader-silabs.js, checking for a crc mismatch(isCrcMismatch function) in the xml packages. If there is a crc mismatch in any of the xml packages then deleting it's parent package which in turn has a cascading effect on deleting all the child packages under the parent packages. After deletion, all the packages are reloaded again to make sure that the schema is validated properly.
- Updating the zap schema
- JIRA: ZAPP-1079
@brdandu brdandu force-pushed the bug/removeDuplicateEntriesFromAttributeTables/ZAPP-1079 branch from 475e6f5 to 7e204ae Compare May 5, 2023 15:34
- The old .zap files have duplicate entries of attributes and commands so having the unique constraint prevents the zap file from being loaded when there are duplicate endpoint type attributes in the .zap file
- Add this back once ZAPP-1192 is resolved
- JIRA: ZAPP-1079
- There are 2 use cases where custom xml changes needed to be reflected in the backend when a user updates the custom xml.
- The first use case is related to user editing the custom xml, deleting it from zcl extensions and then re-adding it. This flow should make sure that the configuration is updated in the backend after this change. See zcl-loader#qualifyZclFile
- The second use case is when the custom xml is already saved as a reference in the .zap config file. In this case if the custom xml file is edited then the next time the .zap file is re-opened then the backend should reflect this change as well. See import-json#jsonDataLoader
- JIRA: ZAPP-1079
`CRC missmatch for file ${pkg.path}, (${pkg.crc} vs ${actualCrc}) package id ${pkg.id}, parsing.
Deleting package id: ${packageId}`
)
await queryPackage.deletePackagesByPackageId(db, packageId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't just delete this package. There might have been another session opened which uses this package.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest you load this new package as well, and then make the session use this new package, not the old package. There is no problems if you have multiple standalone packages.

// is re-opened then the custom xml is reloaded to reflect the correct
// configuration.
if (pkg.type == 'zcl-xml-standalone') {
let info = await queryPackage.getPackageByPackageId(db, packageId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought we have a function for this somewhere. util.readFileContentsAndCrc() or something?

// This check makes sure that when a custom xml is edited, deleted and
// re-added from ZCL Extensions in ZAP UI then the custom xml package is
// updated in the backend to reflect the right configuration.
await queryPackage.deletePackagesByPackageId(db, pkg.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This deleting of packages still sounds dangerous. How do you know there isn't another session using this package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is done when the zcl loading happens. Is it possible to have loading happen when an existing session is still in progress?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry ignore me. This is the custom xml through zcl extension. I see your point.

@paulr34
Copy link
Collaborator

paulr34 commented Feb 27, 2024

@brdandu this bug is fixed so this PR is not needed, please reopen if I am mistaken! thanks!

@paulr34 paulr34 closed this Feb 27, 2024
@brdandu brdandu reopened this Feb 27, 2024
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.

None yet

4 participants