Skip to content

Reconsider not running convert functions against null values #422

Open
@simonw

Description

@simonw

I just got caught out by the fact that None values are not processed by the .convert() mechanism

def convert_value(v):
bar.update(1)
if not v:
return v
return fn(v)
self.db.register_function(convert_value)

I had run this code while working on #420 and I wasn't sure why it didn't work:

$ sqlite-utils add-column content.db articles score float
$ sqlite-utils convert content.db articles score '
import random
random.seed(10)

def convert(value):
    global random
    return random.random()
'

The reason it didn't work is that the newly added score column was full of null values.

I fixed it by doing this instead:

$ sqlite-utils add-column content.db articles score float --not-null-default 1.0

But this indicates to me that the design of convert() here may be incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions