question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom TYPE_MAPPING

See original GitHub issue

I am extending the Schema class from marshmallow for my schemas and extending the TYPE_MAPPING attribute, but because of these lines here, the ModelConverter doesn’t pick up my changes, because it hardcodes marshmallow’s Schema class.

from datetime import datetime
from marshmallow import Schema

[...]

class BaseSchema(Schema):

    TYPE_MAPPING = Schema.TYPE_MAPPING.copy()
    TYPE_MAPPING.update({
        datetime: APIDateTime,
    })

    def __init__(self, *args, **kwargs):
        if 'strict' not in kwargs:
            kwargs['strict'] = True
        super(BaseSchema, self).__init__(*args, **kwargs)

How do I override the mapping in marshmallow-sqlalchemy for datetime => my own custom field?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fuhrystevecommented, Nov 24, 2015

Hmm, not sure if I am misunderstanding your issue or not, but you could also do something like this if you wanted something resembling a custom TYPE_MAPPING in your BaseSchema:

class BaseSchema(ModelSchema):
    class Meta:
        model_converter = MyDefaultConverter
        # other defaults

class MyModelSchema(BaseSchema):
    class Meta(BaseSchema.Meta):
        # MyModelSchema specific customizations
        pass

The only downside is that you need to remember to have your Meta classes extend BaseSchema.Meta if you want to customize it further.

0reactions
imhoffdcommented, Dec 13, 2015

Awesome, @sloria! Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: Kotlin type in custom type mapping can not be a ... - GitHub
bug: Kotlin type in custom type mapping can not be a Kotlin type #704 ... language = "kotlin" typeMapping = mutableMapOf("JSON" to "kotlin....
Read more >
Entity Framework 6 Code First - Custom Type Mapping
Now I'm wondering if it's possible to define custom type mappings in Entity Framework. Pseudo: public class PhysicalAddressMap : ComplexType<PhysicalAddress>() ...
Read more >
"Custom type mapping for is not specified or is invalid(Need ...
I am configuration "OracleCustomTypeMappingAttribute" attribute though by web.conifg. ... "Custom type mapping for 'QR.iPromansys.Common.UDT.
Read more >
Schema and data type mapping in copy activity - Microsoft Learn
Learn about how copy activity in Azure Data Factory and Azure Synapse Analytics pipelines map schemas and data types from source data to ......
Read more >
Create type mapping - ADM Help Centers - Micro Focus
Create value maps; Supported field type mappings; Mapping multiple types to a single type; Additional type mapping guidelines; Mapping custom ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found