[GH-ISSUE #34] 500 Inernal Server Error while inserting into a table via admin interface #21

Closed
opened 2026-02-26 01:32:55 +03:00 by kerem · 6 comments
Owner

Originally created by @pavdmyt on GitHub (Apr 5, 2016).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/34

Hi,

I'm using sandman2 with PostgreSQL.
Every time inserting data into a table using admin interface I'm receiving this page:

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

However, table becomes updated and selects in psql shows new inserted data.

Originally created by @pavdmyt on GitHub (Apr 5, 2016). Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/34 Hi, I'm using sandman2 with PostgreSQL. Every time inserting data into a table using admin interface I'm receiving this page: ``` Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. ``` However, table becomes updated and selects in `psql` shows new inserted data.
kerem 2026-02-26 01:32:55 +03:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@jeffknupp commented on GitHub (Jul 22, 2016):

I'm not able to reproduce this. Can you give some more info?

<!-- gh-comment-id:234668050 --> @jeffknupp commented on GitHub (Jul 22, 2016): I'm not able to reproduce this. Can you give some more info?
Author
Owner

@Datamance commented on GitHub (Aug 3, 2016):

I'm getting something somewhat similar with sandman2ctl:

[2016-08-02 21:29:13,086] ERROR in app: Exception on /admin/proposals/edit/ [POST]
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1643, in full_dispatch_request
    response = self.process_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1864, in process_response
    self.save_session(ctx.session, response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 926, in save_session
    return self.session_interface.save_session(self, session, response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/sessions.py", line 359, in save_session
    val = self.get_signing_serializer(app).dumps(dict(session))
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 566, in dumps
    rv = self.make_signer(salt).sign(payload)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 412, in sign
    return value + sep + self.get_signature(value)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 347, in get_signature
    key = self.derive_key()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 336, in derive_key
    mac = hmac.new(self.secret_key, digestmod=self.digest_method)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/hmac.py", line 144, in new
    return HMAC(key, msg, digestmod)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/hmac.py", line 42, in __init__
    raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__)
TypeError: key: expected bytes or bytearray, but got 'int'
127.0.0.1 - - [02/Aug/2016 21:29:13] "POST /admin/proposals/edit/?url=%2Fadmin%2Fproposals%2F&id=a41e661c-db3d-44d6-8404-603e30a847ce HTTP/1.1" 500 -
<!-- gh-comment-id:237138275 --> @Datamance commented on GitHub (Aug 3, 2016): I'm getting something somewhat similar with sandman2ctl: ``` [2016-08-02 21:29:13,086] ERROR in app: Exception on /admin/proposals/edit/ [POST] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1988, in wsgi_app response = self.full_dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1643, in full_dispatch_request response = self.process_response(response) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 1864, in process_response self.save_session(ctx.session, response) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/app.py", line 926, in save_session return self.session_interface.save_session(self, session, response) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/flask/sessions.py", line 359, in save_session val = self.get_signing_serializer(app).dumps(dict(session)) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 566, in dumps rv = self.make_signer(salt).sign(payload) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 412, in sign return value + sep + self.get_signature(value) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 347, in get_signature key = self.derive_key() File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/itsdangerous.py", line 336, in derive_key mac = hmac.new(self.secret_key, digestmod=self.digest_method) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/hmac.py", line 144, in new return HMAC(key, msg, digestmod) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/hmac.py", line 42, in __init__ raise TypeError("key: expected bytes or bytearray, but got %r" % type(key).__name__) TypeError: key: expected bytes or bytearray, but got 'int' 127.0.0.1 - - [02/Aug/2016 21:29:13] "POST /admin/proposals/edit/?url=%2Fadmin%2Fproposals%2F&id=a41e661c-db3d-44d6-8404-603e30a847ce HTTP/1.1" 500 - ```
Author
Owner

@jeffknupp commented on GitHub (Aug 3, 2016):

Please try downloading version 0.1.0 from pypi and let me know if you see the same issue

<!-- gh-comment-id:237345256 --> @jeffknupp commented on GitHub (Aug 3, 2016): Please try downloading version `0.1.0` from pypi and let me know if you see the same issue
Author
Owner

@Datamance commented on GitHub (Aug 6, 2016):

@jeffknupp I can actually edit records through the admin interface now, but I still get this error when I try to insert a brand new record:

"sqlalchemy.exc.CompileError: Column 'proposals.id' is marked as a member of the primary key for table 'proposals', but has no Python-side or server-side default generator indicated, nor does it indicate 'autoincrement=True' or 'nullable=True', and no explicit value is passed. Primary key columns typically may not store NULL."

I actually created these tables with my own SQLAlchemy ORM classes using the following mixin:

class BaseEntityMixin(Timestamp):
    """The base model for every modeled entity."""

    @declared_attr
    def __tablename__(cls):
        return inflector.plural(cls.__name__.lower())

    id = Column(UUIDType, default=uuid4, primary_key=True)

    def __repr__(self):
        return '<{entity_type}-{id}>'.format(
            entity_type=self.__class__, id=self.id)

^^^^ you can see above that the mixin had a default python generator. Probably why I never got this error with SQLAlchemy-jsonapi or flask-restless.

Once again, I'm guessing I'll have to extend sandman2.model.Model to make this work. Let me know if you think of any other solutions.

<!-- gh-comment-id:238045525 --> @Datamance commented on GitHub (Aug 6, 2016): @jeffknupp I can actually _edit_ records through the admin interface now, but I still get this error when I try to _insert_ a brand new record: _"sqlalchemy.exc.CompileError: Column 'proposals.id' is marked as a member of the primary key for table 'proposals', but **has no Python-side or server-side default generator indicated**, nor does it indicate 'autoincrement=True' or 'nullable=True', and no explicit value is passed. Primary key columns typically may not store NULL."_ I actually created these tables with my own SQLAlchemy ORM classes using the following mixin: ``` class BaseEntityMixin(Timestamp): """The base model for every modeled entity.""" @declared_attr def __tablename__(cls): return inflector.plural(cls.__name__.lower()) id = Column(UUIDType, default=uuid4, primary_key=True) def __repr__(self): return '<{entity_type}-{id}>'.format( entity_type=self.__class__, id=self.id) ``` ^^^^ you can see above that the mixin had a default python generator. Probably why I never got this error with SQLAlchemy-jsonapi or flask-restless. Once again, I'm guessing I'll have to extend sandman2.model.Model to make this work. Let me know if you think of any other solutions.
Author
Owner

@jeffknupp commented on GitHub (Sep 6, 2016):

So the newest version of sandman2 uses a version of SQLAlchemy still in beta (1.0.0b4 I think) that supports "scalar defaults" in the manner you want. Here's the documentation: http://docs.sqlalchemy.org/en/latest/changelog/migration_11.html#new-init-scalar-event-intercepts-default-values-at-orm-level

<!-- gh-comment-id:245032199 --> @jeffknupp commented on GitHub (Sep 6, 2016): So the newest version of `sandman2` uses a version of SQLAlchemy still in beta (1.0.0b4 I think) that supports "scalar defaults" in the manner you want. Here's the documentation: http://docs.sqlalchemy.org/en/latest/changelog/migration_11.html#new-init-scalar-event-intercepts-default-values-at-orm-level
Author
Owner

@jeffknupp commented on GitHub (Sep 20, 2016):

Closing as can not duplicate

<!-- gh-comment-id:248410324 --> @jeffknupp commented on GitHub (Sep 20, 2016): Closing as can not duplicate
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/sandman2-jeffknupp#21
No description provided.