Code Monkey home page Code Monkey logo

Comments (10)

patvdleer avatar patvdleer commented on August 13, 2024

It seems to be the default and not the onupdate, the code below does generate the swagger.json

class CreatedMixin:
    created_at = db.Column(db.DateTime(timezone=True))
    updated_at = db.Column(db.DateTime(timezone=True), onupdate=dt.utcnow)

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

Sorry for not answering earlier. I'll look into it.

I think this will work:

created_at = db.Column(db.DateTime(timezone=True), default=dt.utcnow())

but that's not what you want obv. Will sort it out asap.

from safrs.

patvdleer avatar patvdleer commented on August 13, 2024

No worries, how was your vacation?

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

lol, had a great time, that's why i couldn't reply indeed :)

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

ok, implemented a fix, can you check it works for you?

from safrs.

patvdleer avatar patvdleer commented on August 13, 2024

Sadly no...

from datetime import datetime as dt

# from flask_sqlalchemy import SQLAlchemy
from .extensions import db  # db = SQLAlchemy()

class CreatedMixin:
    created_at = db.Column(db.DateTime(timezone=True), default=dt.utcnow)
    updated_at = db.Column(db.DateTime(timezone=True), default=dt.utcnow, onupdate=dt.utcnow)
[2019-03-26 21:15:24,933] db:589 DEBUG: Failed to get python type for column publisher.created_at
[2019-03-26 21:15:24,934] _api:427 ERROR: <lambda>() missing 1 required positional argument: 'ctx'
Traceback (most recent call last):
  File "/home/patrick/PycharmProjects/ebookhub-backend/venv/src/safrs/safrs/_api.py", line 421, in api_decorator
    decorated_method = swagger_decorator(decorated_method)
  File "/home/patrick/PycharmProjects/ebookhub-backend/venv/src/safrs/safrs/swagger_doc.py", line 383, in swagger_doc_gen
    sample = cls._s_sample_dict()
  File "/home/patrick/PycharmProjects/ebookhub-backend/venv/src/safrs/safrs/db.py", line 592, in _s_sample_dict
    arg = column.default.arg()
TypeError: <lambda>() missing 1 required positional argument: 'ctx'

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

Can you try now? The default arg is ignored now if it's callable.
I'll look at it again later, but callable defaults may cause more issues so I think it's better to just ignore them for now.
The _s_sample_dict is used to generate a sample swagger payload. But when there's a column default, the default will be used so it's not really that important. and the swagger.json can be customized/extended anyway if needed.

from safrs.

patvdleer avatar patvdleer commented on August 13, 2024

The code does run now but throws a bunch of debug messages.

[2019-03-27 11:37:22,185] db:589 DEBUG: Failed to get python type for column publisher.created_at
[2019-03-27 11:37:22,186] db:589 DEBUG: Failed to get python type for column publisher.updated_at
[2019-03-27 11:37:22,251] db:589 DEBUG: Failed to get python type for column publisher.created_at
[2019-03-27 11:37:22,252] db:589 DEBUG: Failed to get python type for column publisher.updated_at
[2019-03-27 11:37:22,252] db:589 DEBUG: Failed to get python type for column publisher.created_at
[2019-03-27 11:37:22,253] db:589 DEBUG: Failed to get python type for column publisher.updated_at

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

This message should be gone now.

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

fixed in v2.1.0

from safrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.