Code Monkey home page Code Monkey logo

blog-code-samples's People

Contributors

bobthemighty avatar hjwp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blog-code-samples's Issues

TypeError: function() argument 1 must be code, not str

Hi, thanks for the interesting blog!

I've run into an issue with this code that I can't work out - it doesn't help that I haven't used the NamedTuple datatype before.

When I try and define a Command object I get a TypeError.

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    class ReportIssueCommand(NamedTuple):
TypeError: function() argument 1 must be code, not str

This happens with simply the following:

from typing import NamedTuple

class ReportIssueCommand(NamedTuple):
    pass

Do you have any advise on how to proceed? Many thanks

Tests are not passing

Hello, i have just cloned the repo, followed instructions to deploy the code and got this error after trying to run tests:

File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/issues/quick_tests/test_assignment.py", line 3, in <module>
    from .adapters import FakeUnitOfWork, FakeEmailSender, FakeViewBuilder
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/issues/quick_tests/adapters.py", line 4, in <module>
    from issues.domain.emails import EmailSender
ModuleNotFoundError: No module named 'issues.domain.emails'

And this is correct, because there are no emails module in the repo (step 04).

Error handling for commands

The ports and adapters example is really, really great. This series is the most readable assembly of this set of concepts that I have seen so far, and I think this style of architecture is one that people could benefit from using a lot more.

Something I took note of as I was reading through was that you never really touched on error handling. If CQS dictates that no values are returned when you're writing data, what do you do if some invariant is violated and thus you can't write the data?

Do you raise an exception? (which is a kind of return value, albeit one intended for unexpected cases)

Do you instead have validation at another layer, doing a Query to inspect what the command is trying to do before running the Command?

Here's an example: what if the assignee for an issue had to be one of a known list? Where would you check that?

I have thoughts on approaches to this, but I'm curious to know how you handle the situation in the architecture you've built up.

Thanks for putting the effort into this!

How to inject the repositories into UnitOfWork class instead of declaring them?

Hi
I stumbled upon this repository and blog posts from this reddit comment thread.

Thanks a lot for the blog posts and the code. It has been very helpful.

I had a question though. In one of the reddit comments you mentioned that it is possible to inject the repository objects instead of defining them as properties like so.

Could you please provide and example or point me to some article or git repo that shows how to do it?

Thanks again.

flask run not working

Hello again, flask run is not working due to missing config module:

(env) ➜  04 git:(master) ✗ flask run
Traceback (most recent call last):
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/bin/flask", line 11, in <module>
    sys.exit(main())
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 513, in main
    cli.main(args=args, prog_name=name)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 380, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 423, in run_command
    app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 152, in __init__
    self._load_unlocked()
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 176, in _load_unlocked
    self._app = rv = self.loader()
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 237, in load_app
    rv = locate_app(self.app_import_path)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/env/lib/python3.6/site-packages/flask/cli.py", line 90, in locate_app
    __import__(module)
  File "/Users/asyncee/blog-code-samples/ports-and-adapters/04/issues/adapters/flask.py", line 3, in <module>
    from . import config
ImportError: cannot import name 'config'

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.