Skip to content

Insert NULL in a boolean column returns no rows #288

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

Closed
mickey opened this issue Apr 7, 2019 · 2 comments · Fixed by #289
Closed

Insert NULL in a boolean column returns no rows #288

mickey opened this issue Apr 7, 2019 · 2 comments · Fixed by #289

Comments

@mickey
Copy link
Contributor

mickey commented Apr 7, 2019

Hello,
Here's a test case that fails:

def test_tiny_maps_to_none_2(self):
    create_query = "CREATE TABLE test (test BOOLEAN)"
    insert_query = "INSERT INTO test VALUES(NULL)"
    event = self.create_and_insert_value(create_query, insert_query)
    self.assertEqual(event.rows[0]["values"]["test"], None)

In this case, event.rows returns [] while event.columns[0].name successfully returns test.
Of course if I have more than 1 row, it works as demonstrated in your test case here.

@mickey mickey changed the title Insert only a boolean value at NULL returns no rows Insert NULL in a boolean column returns no rows Apr 7, 2019
@mickey
Copy link
Contributor Author

mickey commented Apr 7, 2019

I dabbled quickly with the code and it seems that changing:

https://github.com/noplay/python-mysql-replication/blob/07e18b3c89f344db70cb968275ec0ef16d76d2cc/pymysqlreplication/row_event.py#L421-L422

to:

while self.packet.read_bytes + 1 <= self.event_size:
    self.__rows.append(self._fetch_one_row())

See the < VS <=.

The tests are passing but I don't understand the code enough to do a PR before some approval (I'd love an explanation too - if it makes any sense of course 😬).

@baloo
Copy link
Collaborator

baloo commented Apr 8, 2019

I'd say this is an off by one error. I have no idea why though :x.

If you could throw a pr like:

 while self.packet.read_bytes < self.event_size:
    self.__rows.append(self._fetch_one_row())

Just removing the +1 and with your test case, that would be appreciated :)

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 a pull request may close this issue.

2 participants