Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#1213 closed defect (fixed)

Value of NOT_PROVIDED might collide with real data

Reported by: akaihola Owned by: adrian
Component: Database layer (models, ORM) Version:
Severity: trivial Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In django.core.meta.fields, NOT_PROVIDED is defined as

# Random entropy string used by "default" param.
NOT_PROVIDED = 'oijpwojefiojpanv'

Although extremely unlikely, this string could appear as a default value in a model and be interpreted as if no default value was provided.

Is there something preventing the following:

class NOT_PROVIDED:
    pass

Or are there some control characters in the range chr(0..31) which don't make sense in the database backend side and could be used here?

Change History (2)

comment:1 Changed 10 years ago by akaihola <antti.kaihola@…>

Or what about this solution:

class NotProvided(str):
    pass

NOT_PROVIDED = NotProvided('No default value is provided.')

if some_default_value is NOT_PROVIDED:
   print 'There is no default value.'
   # and act accordingly

comment:2 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2454]) Fixed #1213 -- Changed value of NOT_PROVIDED so that it's not a string, to prevent possible (but highly unlikely) collisions. Thanks, akaihola

Note: See TracTickets for help on using tickets.
Back to Top