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

Fix Id Not Specified on Update Call #3761

Merged
merged 3 commits into from
Mar 5, 2024
Merged

Fix Id Not Specified on Update Call #3761

merged 3 commits into from
Mar 5, 2024

Conversation

aditya-balachander
Copy link
Contributor

W-15182566

These modifications address the error reported in Slack Thread

Error Reason:
The old format of sql files use the id field to be of type INTEGER:

CREATE TABLE "accounts" (
	id INTEGER NOT NULL, 
	"Name" VARCHAR(255), 
	"parent_id" VARCHAR(255), 
	PRIMARY KEY (id)
);
INSERT INTO "accounts" VALUES(1,'Bluth','');
INSERT INTO "accounts" VALUES(2,'Funke-Bluth',1);

During handling of adding the outerjoins for lookups, when we specified the condition, we were concatenating a string with an integer:

def join_for_lookup(lookup):
            key_field = lookup.get_lookup_key_field(self.model)
            value_column = getattr(self.model, key_field)
            if self._old_format:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id
                    == str(lookup.table) + "-" + value_column,
                    # Here value_column can be an integer in old format
                )
            else:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id == value_column,
                )

This resulted in the query not returning anything during the update call of the record. Hence the error, Id not specified in an update call

Solution:

We have updated the condition to cast the id column to a string so that successful concatenation happens.

def join_for_lookup(lookup):
            key_field = lookup.get_lookup_key_field(self.model)
            value_column = getattr(self.model, key_field)
            if self._old_format:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id
                    == str(lookup.table) + "-" + func.cast(value_column, String),
                )
            else:
                return (
                    lookup.aliased_table,
                    lookup.aliased_table.columns.id == value_column,
                )

@aditya-balachander aditya-balachander requested a review from a team as a code owner March 5, 2024 10:23
@aditya-balachander aditya-balachander requested a review from jstvz March 5, 2024 10:23
@aditya-balachander aditya-balachander changed the title Fixes Id Not Specified on Update Call Fix Id Not Specified on Update Call Mar 5, 2024
Copy link
Contributor

@jstvz jstvz left a comment

Choose a reason for hiding this comment

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

LGTM

@jstvz jstvz merged commit 260cc76 into main Mar 5, 2024
21 of 23 checks passed
@jstvz jstvz deleted the bug/no_id_on_update branch March 5, 2024 19:00
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.

2 participants