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

Allow to set createdAt and updatedAt during data import(s) #7447

Closed
3 tasks done
sadortun opened this issue Jun 26, 2021 · 14 comments · Fixed by #8696
Closed
3 tasks done

Allow to set createdAt and updatedAt during data import(s) #7447

sadortun opened this issue Jun 26, 2021 · 14 comments · Fixed by #8696
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:feature New feature or improvement of existing feature

Comments

@sadortun
Copy link
Contributor

sadortun commented Jun 26, 2021

New Feature / Enhancement Checklist

Current Limitation

I'm sure it was discussed somewhere, but i could not find anything.

Currently when you import data from a different source, there is no way to set createdAt and updatedAt fields to the existing value of the imported source.

Feature / Enhancement Description

I'm not sure if theses fields have an impact of core parse functionalities, but here is a few suggestions:

  • When creating a new object, If createdAt or updatedAt fields exists and have a valid value, use theses values. Leave as-is when updating an object
  • Add a flag/option in Parse.Object.save() to indicate you want to preserve theses fields.

Example Use Case

In our app we allow users to import transactions from various sources. Currently we need to save the transaction date into a separate field since createdAt is not usable.

In a few other projects, we are syncing data from a 3rd party into Parse DB, and since we cannot use createdAt to store the event creation date, we need to store this in a separate field. This cause confusion, since its not clear why you have two fields to store the parse object creation and event creation

Alternatives / Workarounds

  1. Add user's createdAt/updatedAt values into new fields userCreatedAt and userUpdatedAt
  2. Add all objects
  3. Use MongoDB adapter to update createdAt = userCreatedAt

3rd Party References

@mtrezza
Copy link
Member

mtrezza commented Jun 27, 2021

Thanks for suggesting. This seems to be a valid use case.

In general, even though the createdAt and updatedAt fields are Parse Object meta fields, they are often used implicitly as data fields. This is a fair usage because:

  • Semantically, createdAt / updatedAt are obvious and simple field names for when an object has been created / updated.
  • Not having to add additional date fields saves data traffic and DB storage.

If being used as a data field, it should be possible to set it on object creation, but also to edit when updating an existing object.

There should be no substantial implication in the server or SDKs because being date fields, it would be unreliable to draw any conclusion about the object state. If there was indeed object state logic depending on these fields, removing these dependencies would be an improvement as a side effect of this PR.

Do you want to look into this and open a PR?

(Note: I removed the link to your product as advertising; it is not relevant to this issue.)

@sadortun
Copy link
Contributor Author

I'll try to have a look, but I want to complete.the others PRs before.

It might take some time but I'll try a few things out.

@cbaker6
Copy link
Contributor

cbaker6 commented Jun 27, 2021

There should be no substantial implication in the server or SDKs because being date fields, it would be unreliable to draw any conclusion about the object state. If there was indeed object state logic depending on these fields, removing these dependencies would be an improvement as a side effect of this PR.

Currently, the allowCustomObjectId setting uses createdAt in the JS and Swift SDK do determine if an object should be saved/updated (.POST/.PUT) to the server.

JS: https://github.com/parse-community/Parse-SDK-JS/blob/ffc523f9cd0fa2dd3fcc9754d5f15c3c1c78314f/src/ParseObject.js#L326-L348

Swift:

The potential of this PR seems like there will need to more items resolved before it can be implemented. Currently, the Server can accept ParseObjects with/without custom objectId’s from clients when allowCustomObjectId = true. It doesn’t seem like this would be the case if this PR is implemented. The server PR that enabled customObjectId’s is #6177

If this does end up being implemented, I recommend it has an on/off feature and it should be off by default.

@mtrezza
Copy link
Member

mtrezza commented Jun 27, 2021

Currently, the allowCustomObjectId setting uses createdAt in the JS and Swift SDK do determine if an object should be saved/updated (.POST/.PUT) to the server.

It only determines whether createdAt exists, not its value. If we establish the rule that a saved object always must have a createdAt / updatedAt, that shouldn't interfere (much).

The approaches you referenced seem a bit flawed anyway. Various ways to determine whether an object has been saved or not, depending on whether custom obj id is set, looks too complex with the potential for ambiguity, as we see now with this proposed change.

@sadortun
Copy link
Contributor Author

sadortun commented Jun 27, 2021

@cbaker6 my idea for a first step would be ONLY for freshly created objects.

IFF you save a new object, and the object contains updatedAt/createdAt theses value would be used instead of the generated one on the server.

** Actually, I really only care about createdAt. I'm not sure if overwriting updatedAt make sense anyway. **

So I think this PR scope will be limited to :

  • freshly created objects
  • that contains a valid createdAt
  • provided date < now()

It will also reduce the required changes and avoid nasty side effects.

Would that solve the problem for the API clients ?

@cbaker6
Copy link
Contributor

cbaker6 commented Jun 27, 2021

The approaches you referenced seem a bit flawed anyway. Various ways to determine whether an object has been saved or not, depending on whether custom obj id is set, looks too complex with the potential for ambiguity, as we see now with this proposed change.

All of the SDKs use objectId to determine if an object has been saved already. Using createdAt to determine if the object has actually been saved to the server based on createdAt and updatedAt being server business logic sounds like a reasonable iteration to me. Then again, I was not part of those discussions. If there needs to be a different way to enable the PR in this thread? What would it be?

@cbaker6
Copy link
Contributor

cbaker6 commented Jun 27, 2021

Would that solve the problem for the API clients ?

I’m not sure... I made my comment just to mention that createdAt is currently used to determine state on the client side which effects how it sends data to the server.

@stewones
Copy link
Contributor

stewones commented Jul 6, 2021

This feature would be appreciated. Currently I connect to mongodb manually from my seed scripts to populate createdAt and updatedAt. curious to know, would this be a bad practice? Meaning is there any side effect in terms of how parse stores these fields internally?

@mtrezza mtrezza changed the title 📆 Allow to set createdAt and updatedAt during data import(s) Allow to set createdAt and updatedAt during data import(s) Jul 11, 2021
@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.4.0-alpha.4

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Sep 29, 2023
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Nov 16, 2023
@sadortun
Copy link
Contributor Author

Amaizing work guys ! 🚀

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0-alpha.1

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.5.0

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 7.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:feature New feature or improvement of existing feature
Projects
None yet
5 participants