# Buggy code
def save(self, no_signals=False, commit=True, **kwargs):
    """
    Args:
        commit: True if model should be really saved
    """
    # delete template cache
    if hasattr(self, "_template_cache"):
        delattr(self, "_template_cache")

    created = not bool(self.pk)
    if self.reverse_id == "":
        self.reverse_id = None
    if self.application_namespace == "":
        self.application_namespace = None
    from cms.utils.permissions import _thread_locals

    user = getattr(_thread_locals, "user", None)
    if user:
        try:
            self.changed_by = str(user)
        except AttributeError:
            # AnonymousUser may not have USERNAME_FIELD
            self.changed_by = "anonymous"
    else:
        self.changed_by = "script"
    if created:
        self.created_by = self.changed_by
    if commit:
        if not self.depth:
            if self.parent_id:
                self.parent.add_child(instance=self)
            else:
                self.add_root(instance=self)
            return  # add_root and add_child save as well
        super(Page, self).save(**kwargs)


# Traceback (psycopg2.DataError)
Internal Server Error: /admin/cms/page/add/
Traceback (most recent call last):
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.DataError: value too long for type character varying(70)


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 111, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/contrib/admin/options.py", line 583, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 105, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 206, in inner
return view(request, *args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/cms/admin/pageadmin.py", line 406, in add_view
return super(PageAdmin, self).add_view(request, form_url, extra_context=extra_context)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1453, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
return bound_func(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 105, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/transaction.py", line 394, in inner
return func(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1404, in changeform_view
self.save_model(request, new_object, form, not add)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/cms/admin/pageadmin.py", line 206, in save_model
obj.save()
File "/home/flyweb/www/venv/lib/python3.4/site-packages/cms/models/pagemodel.py", line 457, in save
super(Page, self).save(**kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/mptt/models.py", line 838, in save
super(MPTTModel, self).save(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/cms/models/pagemodel.py", line 475, in save_base
ret = super(Page, self).save_base(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/base.py", line 698, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/base.py", line 731, in _do_insert
using=using, raw=raw)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/query.py", line 921, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
cursor.execute(sql, params)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/home/flyweb/www/venv/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(70)```

# Fixed code
def save(self, no_signals=False, commit=True, **kwargs):
    """
    Args:
        commit: True if model should be really saved
    """
    # delete template cache
    if hasattr(self, "_template_cache"):
        delattr(self, "_template_cache")

    created = not bool(self.pk)
    if self.reverse_id == "":
        self.reverse_id = None
    if self.application_namespace == "":
        self.application_namespace = None
    from cms.utils.permissions import _thread_locals

    user = getattr(_thread_locals, "user", None)
    if user:
        try:
            changed_by = force_text(user)
        except AttributeError:
            # AnonymousUser may not have USERNAME_FIELD
            changed_by = "anonymous"
        else:
            # limit changed_by and created_by to avoid problems with Custom User Model
            if len(changed_by) > constants.PAGE_USERNAME_MAX_LENGTH:
                changed_by = "{0}... (id={1})".format(
                    changed_by[: constants.PAGE_USERNAME_MAX_LENGTH - 15],
                    user.pk,
                )

        self.changed_by = changed_by

    else:
        self.changed_by = "script"
    if created:
        self.created_by = self.changed_by

    if commit:
        if not self.depth:
            if self.parent_id:
                self.parent.add_child(instance=self)
            else:
                self.add_root(instance=self)
            return  # add_root and add_child save as well
        super(Page, self).save(**kwargs)