Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6881877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:11:05+00:00 2026-05-27T05:11:05+00:00

I’m using google app engine/python. And I have created a custom datatype and property.

  • 0

I’m using google app engine/python. And I have created a custom datatype and property. But I have problem using it. This is my definition

from datetime import datetime

class MyDateTime(datetime):
    def __str__(self):
        return self.strftime("%Y-%m-%d %H:%M")

class MyDateTimeProperty(db.Property):
    # specify datatype
    data_type = MyDateTime

    # For writing to datastore.
    def get_value_for_datastore(self, model_instance):
        return super(MyDateTimeProperty, self).get_value_for_datastore(model_instance)

    # For reading from datastore.
    def make_value_from_datastore(self, value):
        return super(MyDateTimeProperty, self).validate(value)

class MyClass(db.Model):
    date = MyDateTimeProperty()

and this is how I use it:

obj = MyClass(date=MyDateTime(2011,1,1))
obj.put()

and I got the following error message:

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\admin\__init__.py", line 295, in post
    exec(compiled_code, globals())
  File "<string>", line 23, in <module>
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1052, in put
    self._populate_internal_entity()
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1020, in _populate_internal_entity
    self._entity = self._populate_entity(_entity_class=_entity_class)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1092, in _populate_entity
    self._to_entity(entity)
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 1005, in _to_entity
    self.__set_property(entity, prop.name, prop.get_value_for_datastore(self))
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\db\__init__.py", line 995, in __set_property
    entity[name] = datastore_value
  File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore.py", line 881, in __setitem__
    datastore_types.ValidateProperty(name, value)
  File "C:\Program Files\Google\google_appengine\google\appengine\api\datastore_types.py", line 1477, in ValidateProperty
    'Unsupported type for property %s: %s' % (name, v.__class__))
BadValueError: Unsupported type for property date: <class '__main__.MyDateTime'>

I’ve searched for solution for a while and could not solve it. Thanks in advance if anyone knows how to fix it.


thanks for the answer. I figured out that the prime problem is that custom data type can’t go into datastore, so I need to wrap/unwrap the custom datatype to/from usual datatype using get_value_for_datastore and make_value_from_datastore

this is my modified property definition:

class MyDateTimeProperty(db.Property):
    # specify datatype
    data_type = MyDateTime

    # For writing to datastore.
    def get_value_for_datastore(self, model_instance):
        date = super(MyDateTimeProperty, self).get_value_for_datastore(model_instance)
        return datetime(date.year, date.month, date.day, date.hour, date.minute)

    # For reading from datastore.
    def make_value_from_datastore(self, value):
        if value is None:
            return None
        return MyDateTime(value.year, value.month, value.day, value.hour, value.minute)

The key is, using get_value_for datastore to change an unstorable MyDateTime object to storable datetime object, and make_value_from_datastore vice versa.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:11:05+00:00Added an answer on May 27, 2026 at 5:11 am

    Your Property subclass needs to define a validate() method if its datatype isn’t one of the defined datastore data types that the default validator knows about. There’s an example validator method in this article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.