Skip to content

Allow blocks to override Field defaults without copying the original field #169

Open

Description

@cpennington

Currently, to change the default value of a field (such as display_name), a block needs to copy the definition. This means that if other values in the field need to change, they need to be changed in many places, which is subpar.

Activity

  1. cpennington commented on Jan 24, 2014

    @cpennington
    ContributorAuthor

    When this happens, accidentally overriding a field should raise an exception.

    Proposal:

    class FooBlock(XBlock):
        display_name = OverrideField(default='Foo Block')  # Uses the same field definition as the parent, with kwargs overridden
        tags = Field(...)  # raises an exception, because it hides a parent field
        name = OverrideField(scope=scope.user_state)  # Error, can't override the scope
    
  2. cpennington commented on Jan 24, 2014

    @cpennington
    ContributorAuthor
  3. nedbat commented on Jan 27, 2014

    @nedbat
    Contributor

    How often has a subclass wanted to keep a field but change its default? This seems like an odd operation to me. There must be some real examples we can look at, I know you didn't invent this for the fun of it.

  4. cpennington commented on Jan 27, 2014

    @cpennington
    ContributorAuthor

    We do it constantly for display_name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions