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

deleteRecord does not set hasDirtyAttributes to true #9053

Open
jayseo5953 opened this issue Oct 24, 2023 · 8 comments
Open

deleteRecord does not set hasDirtyAttributes to true #9053

jayseo5953 opened this issue Oct 24, 2023 · 8 comments
Labels
backport-old-release PR targets a previous non-lts release 🏷️ bug This PR primarily fixes a reported issue lts-4-12 Long Term LTS Maintenance

Comments

@jayseo5953
Copy link

jayseo5953 commented Oct 24, 2023

Reproduction

Please provide one of the following:

Description

  • Have a persisted model (order)
  • Delete record using order.deleteRecord()
  • Check order.isDeleted is true
  • But order.hasDirtyAttributes is false
  • Also order.rollbackAttributes() revert isDeleted to false

Versions

  • "ember-cli": "4.4.1",
  • "ember-source": "~4.4.0"
  • "ember-data": "~4.4.0"
@runspired
Copy link
Contributor

This was fixed in later versions. Broad strokes hasDirtyAttributes responding true for isDeleted is a mistake we don't want to carry forward to the replacement for @ember-data/model but it is one we intend to support until then.

If @fivetanley or @richgt wants to get this change into 4.4 then it shouldn't be hard to backport.

@runspired runspired added 🏷️ bug This PR primarily fixes a reported issue backport-old-release PR targets a previous non-lts release labels Oct 25, 2023
@jayseo5953
Copy link
Author

@runspired sorry do you mean hasDirtyAttributes being set to true by deleteRecord is a mistake?
the document says otherwise tho https://api.emberjs.com/ember-data/4.4/classes/Model/properties/isDeleted?anchor=isDeleted

@runspired
Copy link
Contributor

@jayseo5953 yes, it was a mistake that we did that is what I mean. hasDirtyAttributes should mean only "do I have dirty attributes" not "do I have dirty attributes or am I deleted".

Newer cache APIs allow us to differentiate these things and also provide access to whether relationships are dirty. We should likely have a single isDirty check that is a macro across cache.isDeleted / cache.isNew / cache.hasChangedAttrs / cache.hasChangedRelationships

@jayseo5953
Copy link
Author

@runspired right ok thanks for confirmation. Maybe the doc needs editing then?

@runspired
Copy link
Contributor

@jayseo5953 no the docs are right and its a bug that in 4.4 it doesn't work that way. There's two different points being made here:

  1. that there is a bug in 4.4 that is fixed in later releases that maybe we should backport to 4.4
  2. that the bug is due to us supporting an undesirable behavior which we want to change in the future

I only mention (2) because for folks converting from @ember-data/model to @warp-drive/schema-record the 1:1 migration path will be to check both [STATE].isDeleted and [STATE].hasChangedAttrs, and to a certain degree its probably better to bake the assumption that you need to check both into your code in advance.

@jayseo5953
Copy link
Author

jayseo5953 commented Oct 25, 2023

@runspired would you be able to point me to the closest version that has the fix? if it was fixed in minor versions

@runspired
Copy link
Contributor

@jayseo5953 according to git blame the fix was part of this PR #8849 (I recalled it being older than this but alas). That PR is currently part of 5.3, but we intend to port its work back to the 4.12 LTS

@jayseo5953
Copy link
Author

@runspired thank you!

@runspired runspired added the lts-4-12 Long Term LTS Maintenance label Nov 17, 2023
@runspired runspired moved this from needs triage to stalled in EmberData Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-old-release PR targets a previous non-lts release 🏷️ bug This PR primarily fixes a reported issue lts-4-12 Long Term LTS Maintenance
Projects
Status: stalled
Development

No branches or pull requests

2 participants