Ticket #1370 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

dCursorMixin.setFieldVal() can improperly set value if current value is None

Reported by: JacekK Assigned to: somebody
Priority: major Milestone: 0.9.2
Component: db Version: 0.9.1
Keywords: Cc:

Description

Included patch fixes problem with improper function type use in line 961 (isinstance() is designed to object class to class comparison, while fldType variable is class itself).
Second problem is type mapping based on current field value type, which fails if current value equals 'None'.

Attachments

dCursorMixin.py (87.1 kB) - added by JacekK on 08/11/10 14:17:30.
dCursorMixin.py.patch (1.3 kB) - added by JacekK on 08/12/10 12:52:12.

Change History

08/11/10 14:17:30 changed by JacekK

  • attachment dCursorMixin.py added.

(follow-up: ↓ 2 ) 08/12/10 09:52:40 changed by paul

isinstance(rec[fld], cls) is equivalent to issubclass(fldType, cls), no?

So the only substantial change is on line 961, correct?

I'm not against changing these isinstance() calls to issubclass() calls, but I just wanted to make sure I understood the fixes first.

(in reply to: ↑ 1 ) 08/12/10 12:43:05 changed by JacekK

Replying to paul:

isinstance(rec[fld], cls) is equivalent to issubclass(fldType, cls), no?


Not exactly.
While isinstance(0, int) returns True, isinstance(None, int) returns False.
isinstance() function could be right here, if you could prevent situation where rec[fld] = None. But you can't.
But issubclass(int, int) always return True - this is the point of changes.
This is perfectly visible in my MsSQL 'bit' type mapping example.
While it's 'int' type data with range [0, 1], UI layer returns boolean type value instead for bound field.
In such situation conversion fails if isinstance() is used, dataset is incorrectly updated and backend returns exception, like 'Column True not found'.
By using issubclass() function, fields are always updated to value of correct type, regardless previous value is None or not.
I think, there should be yet another change in line 957, to avoid unneeded conversion (e.g. None to 0), from

		if fldType is not None:

to

		if fldType is not None and val is not None:

08/12/10 12:52:12 changed by JacekK

  • attachment dCursorMixin.py.patch added.

12/18/10 14:29:40 changed by JacekK

  • status changed from new to closed.
  • resolution set to fixed.