Skip to content

Commit

Permalink
Merge pull request #332 from phenobarbital/dev
Browse files Browse the repository at this point in the history
fix on ModelView for using parse_type from datamodel
  • Loading branch information
phenobarbital authored Jan 14, 2025
2 parents 2d27ab6 + 8f47196 commit d8dd7ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
23 changes: 21 additions & 2 deletions examples/handler.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import asyncio
from aiohttp import web
from navigator import Application
from navigator.background import BackgroundQueue
from app import Main


async def blocking_code():
print('Starting blocking code')
await asyncio.sleep(5)
print('Finished blocking code')

async def done_blocking(*args, **kwargs):
print('Done Blocking Code :::')

async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
queue = request.app['service_queue']
# future = asyncio.create_task(blocking_code())
await queue.put(blocking_code)
# queue.add_callback(done_blocking)
return web.Response(text=text)

app = Application(app=Main)
app = Application()

BackgroundQueue(
app=app,
max_workers=2,
queue_size=4
)

app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])



if __name__ == '__main__':
try:
app.run()
Expand Down
1 change: 1 addition & 0 deletions examples/test_sqs_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def main():
queue = await sqs.create_queue(queue_name)
queue_url = queue.url
print(f"Queue URL: {queue_url}")

# # Publish a JSON Message
# await sqs.publish_message({"key": "value"}, "MyTestQueue")
# # Publish JSONPickle
Expand Down
3 changes: 2 additions & 1 deletion navigator/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
__description__ = (
"Navigator Web Framework based on aiohttp, " "with batteries included."
)
__version__ = "2.12.9"
__version__ = "2.12.10"
__copyright__ = "Copyright (c) 2020-2024 Jesus Lara"
__author__ = "Jesus Lara"
__author_email__ = "[email protected]"
__license__ = "BSD"
9 changes: 3 additions & 6 deletions navigator/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,9 @@ async def _set_update(self, model, data):
model.set(key, newval)
continue
try:
newval = parse_type(col.type, val)
newval = parse_type(col, col.type, val)
except ValueError:
if col.type == str:
newval = str(val)
else:
newval = val
newval = str(val) if col.type == str else val
model.set(key, newval)

async def _patch_data(self, *args, **kwargs) -> Any:
Expand Down Expand Up @@ -802,7 +799,7 @@ async def patch(self):
# Patching one Single Attribute:
if _attribute in obj.get_fields():
col = obj.column(_attribute)
newval = parse_type(col.type, data)
newval = parse_type(col, col.type, data)
obj.set(_attribute, newval)
result = await obj.update()
return await self._patch_response(result, status=202)
Expand Down

0 comments on commit d8dd7ee

Please sign in to comment.