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

[Tax] add FK to tax/sales_order_tax again #4334

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

Conversation

Hanmac
Copy link
Contributor

@Hanmac Hanmac commented Nov 4, 2024

Description (*)

This Fixes the Missing FK between sales_order_tax and sales_flat_order

Right now, when an order gets deleted, the cascade deletes the sales_flat_order_item
and then the cascade deletes sales_order_tax_item,
but sales_order_tax stays with now the order_id pointing to an order that doesn't exist anymore.

That could cause in the wrong taxes to be displayed.

The FK existed before as FK_SALES_ORDER_TAX_ORDER, but got removed ages ago.

The only other tables that misses the FK are these ones, but they are referenced via creditmemo/invoice/shipment:

  • sales_flat_creditmemo_grid
  • sales_flat_invoice_grid
  • sales_flat_shipment_grid
  • sales_flat_shipment_track

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: Tax Relates to Mage_Tax label Nov 4, 2024
@Hanmac Hanmac marked this pull request as ready for review November 4, 2024 16:09
@Hanmac
Copy link
Contributor Author

Hanmac commented Nov 5, 2024

@sreichel should be easy to merge? Or is it controversial?

@kiatng
Copy link
Contributor

kiatng commented Nov 6, 2024

Any idea why was the FK dropped? For stores with large tables, I often experienced MySQL timeout or errors when adding index or modifying tables. Is this update safe? Will it break production?

@Hanmac
Copy link
Contributor Author

Hanmac commented Nov 6, 2024

Any idea why was the FK dropped? For stores with large tables, I often experienced MySQL timeout or errors when adding index or modifying tables. Is this update safe? Will it break production?

The FK there should be minimal, sales_order_tax isn't called that often without Order anyway.

@sreichel
Copy link
Contributor

sreichel commented Nov 6, 2024

@sreichel should be easy to merge? Or is it controversial?

lgtm. Just dont know why it has been changed.

@Hanmac
Copy link
Contributor Author

Hanmac commented Nov 6, 2024

It's 13–14 years ago, probably no one remembers that

@sreichel
Copy link
Contributor

sreichel commented Nov 7, 2024

Some times you find something in release notes or stackexchange ... but no.

sreichel
sreichel previously approved these changes Nov 7, 2024
@kiatng
Copy link
Contributor

kiatng commented Nov 10, 2024

I am still not sure:

  1. For large table, timeout may occur, I have a million entries in production
  2. Missing orders in the sales table, meaning orphaned records in the tax table, MySQL may complain.

For ref, cursor AI suggest this:

// First, clean up orphaned records
$this->getConnection()->query("
    DELETE t FROM {$taxTable} t 
    LEFT JOIN {$orderTable} o ON t.order_id = o.entity_id 
    WHERE o.entity_id IS NULL
");

@Hanmac
Copy link
Contributor Author

Hanmac commented Nov 10, 2024

@kiatng yeah I should probably delete orphaned tax entries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Tax Relates to Mage_Tax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants