Skip to content

OBGM-530 Fix missing requisition sourceType on create request#4132

Merged
awalkowiak merged 1 commit intofeature/upgrade-to-grails-3.3.10from
OBGM-530-spike-outbound-workflow-visible-instead-of-requests
Jul 3, 2023
Merged

OBGM-530 Fix missing requisition sourceType on create request#4132
awalkowiak merged 1 commit intofeature/upgrade-to-grails-3.3.10from
OBGM-530-spike-outbound-workflow-visible-instead-of-requests

Conversation

@drodzewicz
Copy link
Collaborator

No description provided.

@drodzewicz drodzewicz self-assigned this Jul 3, 2023
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In short, the issue was that

 stockMovement.sourceType = params.sourceType as RequisitionSourceType

was assigning a null value to the sourceType because params.sourceType is null, and also because it is a value from the requests body and not a param.

Although it looked like all I had to do was change params.sourceType to request.JSON.sourceType as we have done before, I noticed that when using the "inferred data binding" like

def create(StockMovement stockMovement) { ...

we lose access to the requets.JSON data.

I did an experiment and removed the StockMovement stockMovemen from the parameters and after that, I had access to request.JSON data.
Just wanted to point this out, not sure if it was already discussed/noticed in my absence and if someone knows what's up the let me know.

cc @awalkowiak @kchelstowski @alannadolny @jmiranda

Copy link
Member

Choose a reason for hiding this comment

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

@drodzewicz Good catch! Yes, the request.JSON object cannot be accessed twice so once the data is accessed in the command object binding (i.e. populating the StockMovement object), then we're done. The best solution might be to include RequisitionSourceType as a nullable property on StockMovement so it gets bound properly.

To make it backward compatible, we'd need to figure out what was going on in Grails 1. I don't expect this to be true, but maybe it was adding all request.JSON to params so you could access it in either way.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, it looks like RequisitionSourceType is already on StockMovement, so just removing that line (as you did) should take care of the issue. Nice work, guys.

// Detect whether inbound or outbound stock movement
def currentLocation = Location.get(session.warehouse.id)

stockMovement.sourceType = params.sourceType as RequisitionSourceType
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is because parseRequest: true doesn't work anymore in Grails 3 (or even in 2), so as you said -> changing params to request.JSON should be done here, but since you are binding the data in the params, you "lose' the access to that and this is expected behavior, so LGTM

Copy link
Member

Choose a reason for hiding this comment

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

Boom goes the dynamite. Thanks for the reminder @kchelstowski.

@awalkowiak awalkowiak requested a review from jmiranda July 3, 2023 15:08
@awalkowiak awalkowiak merged commit 7ee9ab9 into feature/upgrade-to-grails-3.3.10 Jul 3, 2023
@awalkowiak awalkowiak deleted the OBGM-530-spike-outbound-workflow-visible-instead-of-requests branch July 3, 2023 15:48
Copy link
Member

@jmiranda jmiranda left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants