Skip to content

Fix int arithmetic bug - #1260

Merged
dantownsend merged 10 commits into
piccolo-orm:masterfrom
ryanvarley:fix-int-arithmetic-bug
Oct 11, 2025
Merged

Fix int arithmetic bug#1260
dantownsend merged 10 commits into
piccolo-orm:masterfrom
ryanvarley:fix-int-arithmetic-bug

Conversation

@ryanvarley

@ryanvarley ryanvarley commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

If you subtract two numeric columns from each other piccolo will subtract it from itself.

e.g.

class MyTable(Table):
    integer = Integer(null=True)
    other_integer = Integer(null=True)

print(MyTable.integer - MyTable.other_integer) produces other_integer - other_integer

Issue #1261

@ryanvarley
ryanvarley marked this pull request as draft October 9, 2025 11:11
@ryanvarley ryanvarley closed this Oct 9, 2025
@ryanvarley ryanvarley reopened this Oct 9, 2025

class MyTable(Table):
integer = Integer(null=True)
other_integer = Integer(null=True, default=5)

@ryanvarley ryanvarley Oct 9, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no way i can see of setting initial values on two columns in this test suite so defining here as a demonstration

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that's fine.

Comment thread tests/table/test_update.py Outdated
querystring=MyTable.integer + MyTable.other_integer,
expected=1005,
),
OperatorTestCase(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These wont pass due to >< not being valid operators currently

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, we might have to leave the > and < for another PR.

def get_querystring(
self,
column_name: str,
operator: Literal["+", "-", "/", "*"],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

<> not valid?

@dantownsend dantownsend left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great - thanks!

I'd remove the test cases for > and < for now (we can tackle that in a separate PR) and then I think this is good to go.

Looks like one of our integration tests is failing, but we'll fix that in a separate PR then update this one.

Comment thread tests/table/test_update.py Outdated
querystring=MyTable.integer + MyTable.other_integer,
expected=1005,
),
OperatorTestCase(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, we might have to leave the > and < for another PR.


class MyTable(Table):
integer = Integer(null=True)
other_integer = Integer(null=True, default=5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that's fine.

@dantownsend

Copy link
Copy Markdown
Member

If you update this branch from main, the integration tests should now pass 👍

@dantownsend
dantownsend merged commit dd3002e into piccolo-orm:master Oct 11, 2025
46 checks passed
@dantownsend

Copy link
Copy Markdown
Member

@ryanvarley I went ahead and merged it in, so it can be in the next release. Thanks a lot for this fix 👍

@ryanvarley

Copy link
Copy Markdown
Contributor Author

Awesome, thanks for the quick review!

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