import pytz

from flaskbb.extensions import db


class CRUDMixin(object):
    def __repr__(self):
        return "<{}>".format(self.__class__.__name__)

    def save(self):
        """Saves the object to the database."""
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        """Delete the object from the database."""
        db.session.delete(self)
        db.session.commit()
        return self


class UTCDateTime(db.TypeDecorator):
    impl = db.DateTime

    def process_bind_param(self, value, dialect):
        """Way into the database."""
        if value is not None:
            # store naive datetime for sqlite
            if dialect.name == "sqlite":
                return value.replace(tzinfo=None)

            return value.astimezone(pytz.UTC)

    def process_result_value(self, value, dialect):
        """Way out of the database."""
        # convert naive datetime to non naive datetime
        if dialect.name == "sqlite" and value is not None:
            return value.replace(tzinfo=pytz.UTC)

        # other dialects are already non-naive
        return value

import pytz

from flaskbb.extensions import db


class CRUDMixin(object):
    def __repr__(self):
        return "<{}>".format(self.__class__.__name__)

    def save(self):
        """Saves the object to the database."""
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        """Delete the object from the database."""
        db.session.delete(self)
        db.session.commit()
        return self


class UTCDateTime(db.TypeDecorator):
    impl = db.DateTime

    def process_bind_param(self, value, dialect):
        """Way into the database."""
        if value is not None:
            # store naive datetime for sqlite and mysql
            if dialect.name in ("sqlite", "mysql"):
                return value.replace(tzinfo=None)

            return value.astimezone(pytz.UTC)

    def process_result_value(self, value, dialect):
        """Way out of the database."""
        # convert naive datetime to non naive datetime
        if dialect.name in ("sqlite", "mysql") and value is not None:
            return value.replace(tzinfo=pytz.UTC)

        # other dialects are already non-naive
        return value

Use the naive datetime format for MySQL as well
Use the naive datetime format for MySQL as well

See the SQLAlchemy docs for more information:
http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#sqlalchemy.dial
ects.mysql.DATETIME

  import pytz
  
  from flaskbb.extensions import db
  
  
  class CRUDMixin(object):
      def __repr__(self):
          return "<{}>".format(self.__class__.__name__)
  
      def save(self):
          """Saves the object to the database."""
          db.session.add(self)
          db.session.commit()
          return self
  
      def delete(self):
          """Delete the object from the database."""
          db.session.delete(self)
          db.session.commit()
          return self
  
  
  class UTCDateTime(db.TypeDecorator):
      impl = db.DateTime
  
      def process_bind_param(self, value, dialect):
          """Way into the database."""
          if value is not None:
-             # store naive datetime for sqlite
+             # store naive datetime for sqlite and mysql
-             if dialect.name == "sqlite":
+             if dialect.name in ("sqlite", "mysql"):
                  return value.replace(tzinfo=None)
  
              return value.astimezone(pytz.UTC)
  
      def process_result_value(self, value, dialect):
          """Way out of the database."""
          # convert naive datetime to non naive datetime
-         if dialect.name == "sqlite" and value is not None:
+         if dialect.name in ("sqlite", "mysql") and value is not None:
              return value.replace(tzinfo=pytz.UTC)
  
          # other dialects are already non-naive
          return value
  
Use the naive datetime format for MySQL as well
## Code Before:
import pytz

from flaskbb.extensions import db


class CRUDMixin(object):
    def __repr__(self):
        return "<{}>".format(self.__class__.__name__)

    def save(self):
        """Saves the object to the database."""
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        """Delete the object from the database."""
        db.session.delete(self)
        db.session.commit()
        return self


class UTCDateTime(db.TypeDecorator):
    impl = db.DateTime

    def process_bind_param(self, value, dialect):
        """Way into the database."""
        if value is not None:
            # store naive datetime for sqlite
            if dialect.name == "sqlite":
                return value.replace(tzinfo=None)

            return value.astimezone(pytz.UTC)

    def process_result_value(self, value, dialect):
        """Way out of the database."""
        # convert naive datetime to non naive datetime
        if dialect.name == "sqlite" and value is not None:
            return value.replace(tzinfo=pytz.UTC)

        # other dialects are already non-naive
        return value

## Instruction:
Use the naive datetime format for MySQL as well
## Code After:
import pytz

from flaskbb.extensions import db


class CRUDMixin(object):
    def __repr__(self):
        return "<{}>".format(self.__class__.__name__)

    def save(self):
        """Saves the object to the database."""
        db.session.add(self)
        db.session.commit()
        return self

    def delete(self):
        """Delete the object from the database."""
        db.session.delete(self)
        db.session.commit()
        return self


class UTCDateTime(db.TypeDecorator):
    impl = db.DateTime

    def process_bind_param(self, value, dialect):
        """Way into the database."""
        if value is not None:
            # store naive datetime for sqlite and mysql
            if dialect.name in ("sqlite", "mysql"):
                return value.replace(tzinfo=None)

            return value.astimezone(pytz.UTC)

    def process_result_value(self, value, dialect):
        """Way out of the database."""
        # convert naive datetime to non naive datetime
        if dialect.name in ("sqlite", "mysql") and value is not None:
            return value.replace(tzinfo=pytz.UTC)

        # other dialects are already non-naive
        return value
