question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New PG Range.__eq__() should not raise an exception comparing with a non-Range value

See original GitHub issue

Describe the bug

As written, the method Range.eq() declares its argument as other: Any, but it really expects another instance of the same class, otherwise it raises an exception.

To Reproduce

>>> from sqlalchemy.dialects.postgresql import Range
>>> r = Range(1,10)
>>> r == None

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lele/wip/sqlalchemy/lib/sqlalchemy/dialects/postgresql/ranges.py", line 294, in __eq__
    elif self.empty != other.empty:
AttributeError: 'NoneType' object has no attribute 'empty'

Versions

  • OS: any
  • Python: any
  • SQLAlchemy: 2.0.0b4+
  • Database: irrilevant
  • DBAPI (eg: psycopg, cx_oracle, mysqlclient): irrilevant

Additional context

@CaselIT suggested to return NotImplemented, that seems the right thing to do accordingly to the documentation.

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
CaselITcommented, Dec 15, 2022

no sorry, my mistake. This issue is not closed because it’s missing the “closes / fixes #issue-id” .

The commit message is

Fix equality comparison between a PG Range and a different class inst…

…ance

This fixes issue https://github.com/sqlalchemy/sqlalchemy/issues/8984, making the method `Range.__eq__` return `NotImplemented` when the argument is an instance of a different class.

Closes: https://github.com/sqlalchemy/sqlalchemy/pull/8985
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8985
Pull-request-sha: https://github.com/sqlalchemy/sqlalchemy/commit/b8f601f038a2203af02a99ab190ebbc1c489549a

Change-Id: Iaf0b651a22a9f346c8f18b3a53e3339bf61bb33f

it should be

Fix equality comparison between a PG Range and a different class inst…

…ance

This fixes issue https://github.com/sqlalchemy/sqlalchemy/issues/8984, making the method `Range.__eq__` return `NotImplemented` when the argument is an instance of a different class.

Fixes: #8984
Closes: https://github.com/sqlalchemy/sqlalchemy/pull/8985
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8985
Pull-request-sha: https://github.com/sqlalchemy/sqlalchemy/commit/b8f601f038a2203af02a99ab190ebbc1c489549a

Change-Id: Iaf0b651a22a9f346c8f18b3a53e3339bf61bb33f
0reactions
CaselITcommented, Dec 15, 2022

No problem!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pitfalls to having __eq__ raise an exception? - python
I have a type where equality comparison doesn't make sense. Explicitly comparing two instances of this type for either reference or value ......
Read more >
7.3. Other Comparison Operators
A binary comparison operator compares two variables or quantities. Note that integer and string comparison use a different set of operators. integer comparison....
Read more >
Oracle® Fusion Applications Workforce Development ...
User Guides address the tasks in one or more business processes. They are intended for users who perform these tasks, and managers looking...
Read more >
Diff - 5442ff6bad80f910f84ddf265393796d5fa9d977^2 ... - Google Git
It avoids + // trying to do future verification optimizations when processing the vdex file. + DCHECK(failure_kind == verifier::MethodVerifier::kSoftFailure || ...
Read more >
FICO Xpress Optimizer Python interface Reference Manual
Installing the Xpress Python interface does not require ... The Xpress Python interface raises its own exceptions in the event of a modeling,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found