-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
chore(sqlalchemy): Remove erroneous SQLAlchemy ORM session.merge operations #24776
chore(sqlalchemy): Remove erroneous SQLAlchemy ORM session.merge operations #24776
Conversation
375f79a
to
f34edc5
Compare
Codecov Report
@@ Coverage Diff @@
## master #24776 +/- ##
===========================================
- Coverage 68.96% 58.48% -10.49%
===========================================
Files 1906 1906
Lines 74122 74107 -15
Branches 8208 8208
===========================================
- Hits 51116 43339 -7777
- Misses 20883 28645 +7762
Partials 2123 2123
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 282 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
f34edc5
to
5b429b3
Compare
5b429b3
to
9e6e897
Compare
9e6e897
to
0c55386
Compare
@@ -141,10 +141,9 @@ def upgrade_slice(cls, slc: Slice) -> Slice: | |||
if "form_data" in (query_context := try_load_json(slc.query_context)): | |||
query_context["form_data"] = clz.data | |||
slc.query_context = json.dumps(query_context) | |||
return slc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this was returning the same object as the one being passed in.
9e5d609
to
1b61a9e
Compare
@@ -326,7 +326,8 @@ def virtual_dataset(): | |||
TableColumn(column_name="col5", type="VARCHAR(255)", table=dataset) | |||
|
|||
SqlMetric(metric_name="count", expression="count(*)", table=dataset) | |||
db.session.merge(dataset) | |||
db.session.add(dataset) | |||
db.session.commit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's likely a lot wrong happening here, but committing seems consistent with the logic on lines 334-335.
1b61a9e
to
edc8500
Compare
ping @michael-s-molina |
@@ -87,7 +87,6 @@ def update(self) -> Optional[Key]: | |||
entry.expires_on = self.expires_on | |||
entry.changed_on = datetime.now() | |||
entry.changed_by_fk = get_user_id() | |||
db.session.merge(entry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if the autoflush(False)
when querying for the model influences anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-s-molina I'm not entirely sure why auto-flushing has been disabled here (and elsewhere in the key/value commands). Maybe @villebro can provide some context as this was added in #19078.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-s-molina I removed the unnecessary auto-flush logic in #26009.
7cebf8b
to
46ffd85
Compare
46ffd85
to
77ef809
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
SUMMARY
This PR addresses a non-controversial observation from [SIP-99A] Primer on managing SQLAlchemy sessions where we have a tendency to unnecessarily re-merge objects into the SQLAlchemy session which are already present in the seession.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
CI.
ADDITIONAL INFORMATION