Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Regression in Entity "hiddenProperty" behavior when creating a new entity via SequelizeCrudRepository#create #37

Closed
KalleV opened this issue May 30, 2023 · 2 comments · Fixed by #39
Assignees

Comments

@KalleV
Copy link

KalleV commented May 30, 2023

Describe the bug
I noticed that Entity properties marked as hidden are not accessible immediately after creation using a repository extending the SequelizeCrudRepository.

I traced it to this code:

To Reproduce
Steps to reproduce the behavior:

  1. Create a new entity with a hidden field (e.g. Book with a decorator like "@model( { hiddenProperties: [ 'theEnding' ] } )") using Repository.create()
  2. Try to access the hidden property in the backend code
  3. Error: "Property is undefined"

Expected behavior
Hidden properties should be excluded from the REST API responses but still be accessible in the backend.

Additional context
It seems to be related to this PR: 3e254fd

My understanding is that Loopback will call "toJSON" when serializing the response which should already handle excluding the hidden properties: https://github.com/loopbackio/loopback-next/blob/057150d78908045c3ac2405b0ba2aac65eb17416/packages/repository/src/model.ts#L341-L370

It seems like changing this line:

return new this.entityClass(this.excludeHiddenProps(data.toJSON())) as T;

to the following might be all it takes:

return new this.entityClass(data.toJSON()) as T;
@shubhamp-sf shubhamp-sf self-assigned this May 30, 2023
@shubhamp-sf
Copy link
Collaborator

Loopback will call "toJSON" when serializing the response which should already handle excluding the hidden properties

It does but the model in this case will be sequelize model which doesn't inherit the loopback's model so a way to replicate similar behaviour for sequelize's model class would help. Will se what can be the done for this.

PS: Thanks so much for testing things out for this package. I would appreciate if you could post future issues on loopback-next as It's easier for me to point these issue in fix PRs.

@KalleV
Copy link
Author

KalleV commented May 31, 2023

No problem! I'm eager to get this working. I'll post issues in Loopback Next instead going forward.

RaghavaroraSF added a commit that referenced this issue Jun 12, 2023
Fixed Regression in Entity \"hiddenProperty\" behavior when creating a new entity via
SequelizeCrudRepository#create

GH-37
RaghavaroraSF added a commit that referenced this issue Jun 12, 2023
shubhamp-sf added a commit that referenced this issue Jun 13, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
Which prevented users from accessing those fields on backend.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

GH-37
shubhamp-sf added a commit that referenced this issue Jun 13, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
Which prevented users from accessing those fields on backend.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

GH-37
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 13, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 13, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 14, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 14, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 14, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
shubhamp-sf added a commit to shubhamp-sf/loopback-next that referenced this issue Jun 14, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
dhmlau pushed a commit to loopbackio/loopback-next that referenced this issue Jun 17, 2023
Previously, the package used a custom `excludeHiddenProps` function to exclude hidden fields.
But that prevented users from accessing those fields on backend too.
With this change, we now defer to the LoopBack Model's built-in toJSON method,
which already handles the exclusion of hidden properties when serializing data for a response.

Fixes: sourcefuse/loopback4-sequelize#37

Signed-off-by: Shubham P <shubham.prajapat@sourcefuse.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants