SlideShare a Scribd company logo
1 of 53
Download to read offline
Exceptable



Tuesday, October 20, 2009
Exception Propagation, in
                     PostgreSQL and Python
                        Aurynn Shaw, Commandprompt, Inc.



                             PostgreSQL Conference West, 2009

Tuesday, October 20, 2009
Background


     • Large, enterprise Python + Pylons application
     • Simpycity ORM utilizes significant stored
           procedures

             • Strong procedural interfaces



Tuesday, October 20, 2009
Stored Procedures are Rare



             • Most people don’t use Stored Procedures.




Tuesday, October 20, 2009
The Present System
                              Wherein


        • A Database Query
        • A Stored Procedure
        • Or, A Database Query
        • Exceptions Galore



Tuesday, October 20, 2009
A Database Query



     • The App queries the Database




Tuesday, October 20, 2009
A Database Query



     • The App queries the Database
     • Any variety of query




Tuesday, October 20, 2009
A Database Query
       >>> c.Raw("SELECT * FROM auth_only")()
       Traceback (most recent call last):
       ... <SNIP> ...
       psycopg2.ProgrammingError: permission denied for
       relation auth_only




Tuesday, October 20, 2009
A Database Query


     • The App queries the Database
     • Any variety of query
     • Or A Stored Procedure



Tuesday, October 20, 2009
Or a Stored Procedure
       CREATE OR REPLACE FUNCTION except_test() RETURNS
       VOID AS $$
       BEGIN
                 RAISE EXCEPTION 'Test!';
       END;
       $$ LANGUAGE PLPGSQL;
       >>> c.Function("except_test")()
       Traceback (most recent call last):
         ... <SNIP> ...
       psycopg2.InternalError: Test!



Tuesday, October 20, 2009
Beget an Exception


     • Stored procedures raise InternalErrors
             • Every procedural exception becomes this
     • Permissions violations raise ProgrammingErrors
             • I haven’t tested if this is all PG exceptions.


Tuesday, October 20, 2009
Seriously?



     • This is what we have to work with?




Tuesday, October 20, 2009
Why this is Important
                            Wherein


        • Why?
        • Defining your APIs
        • Separation of Concerns
        • Procedural Spaghetti



Tuesday, October 20, 2009
Why?


     • Limited information to propagate upwards
     • Stored Procedures are Harder to use
     • Permissions violations are difficult to detect



Tuesday, October 20, 2009
API Undefined



     • Exceptions are part of your API




Tuesday, October 20, 2009
API Undefined



     • Exceptions are part of your API
     • Easily overlooked




Tuesday, October 20, 2009
API Undefined


     • Exceptions are part of your API
     • Easily overlooked
     • Delineations will make life easier



Tuesday, October 20, 2009
Separation of Concerns



     • The Database is for Database Logic




Tuesday, October 20, 2009
Separation of Concerns



     • The Database is for Database Logic
     • Harder to write Data Logic




Tuesday, October 20, 2009
Spaghetti
                                   Early version of our
                                   app didn’t have
                                   Exceptable - we
                                   were left catching
                                   InternalErrors and
                                   guessing at what
     • InternalErrors everywhere   the error was, based
                                   on timing.




Tuesday, October 20, 2009
Spaghetti



     • InternalErrors everywhere
     • Insufficiency of Information




Tuesday, October 20, 2009
Spaghetti


     • InternalErrors everywhere
     • Insufficiency of Information
     • Considerable Repeated Code



Tuesday, October 20, 2009
A Saving Grace



     • Violating Procedure Signatures ->
                Python DataError




Tuesday, October 20, 2009
A Better Deal
                               Wherein


        • Database API
        • Easy Python implementation
        • Universality
        • Exceptable



Tuesday, October 20, 2009
Database API



     • Easier to define an API




Tuesday, October 20, 2009
Database API



     • Easier to define an API
     • The DB becomes part of that API




Tuesday, October 20, 2009
Database API


     • Easier to define an API
     • The DB becomes part of that API
     • Simple Stored Procedure interface



Tuesday, October 20, 2009
Database API


     • Easier to define an API
     • The DB becomes part of that API
     • Simple Stored Procedure interface
     • Easily declare new Exceptions


Tuesday, October 20, 2009
Wonderfully Python



     • A Simple Decorator




Tuesday, October 20, 2009
Simply Decorated
       from exceptable.exceptable import Except


       base = Except()


       @base
       def db_function():
            pass




Tuesday, October 20, 2009
Wonderfully Python


     • A Simple Decorator
     • Catches and re-emits Exceptions
             • The core of Exceptable
     • Easy to Integrate - 2 lines, in Simpycity


Tuesday, October 20, 2009
Universality


     • Exceptable Procedures never change
     • DB logic doesn’t change
     • Application support is Easy



Tuesday, October 20, 2009
Exceptable



     • More Pythonic Database Access
     • Better exceptions means better app flow




Tuesday, October 20, 2009
Example Code
                               Wherein


        • The DB Library
        • The Application Implementation
        • Catching Permissions Violations
        • PostgreSQL 8.4



Tuesday, October 20, 2009
To Start,
       CREATE TABLE exceptions (
           name text primary key,
           description text not null,
           parent text references exceptions(name)
       );
       INSERT INTO exceptions VALUES ('Exception',
       'Base exception',NULL);
       INSERT INTO exceptions VALUES
       ('NotFoundException', 'Could not find
       specified record', 'Exception');


Tuesday, October 20, 2009
Which leads to
     CREATE OR REPLACE FUNCTION not_found (
         in_reason TEXT
     ) RETURNS VOID as $body$

         SELECT exceptaple.raise(
                'NotFoundException',
                $1
         );
     $body$ LANGUAGE SQL;



Tuesday, October 20, 2009
Application Level



     • Easy to Query the Exception tables




Tuesday, October 20, 2009
Application Level


     • Easy to Query the Exception tables
     • Easy to set up a new library
             • Python took 50 lines



Tuesday, October 20, 2009
Our Python Example



     • The Exceptable decorator is easy to set up
     • Designed for DB-API integration




Tuesday, October 20, 2009
In the Application
     base = Except(InternalError, {
         'Exception': Exception,
         'NotFoundException': NotFoundError,
     })




Tuesday, October 20, 2009
Our Python Example


     • The Exceptable decorator is easy to set up
     • Designed for DB-API integration
     • User-defined



Tuesday, October 20, 2009
User Definitions
       base = Except(InternalError, {
           'PermissionError': PermissionError,
           'UnknownUser': UnknownUserError,
           'NotFoundException': NotFoundError,
       })




Tuesday, October 20, 2009
Our Python Example


     • The Exceptable decorator is easy to set up
     • Designed for DB-API integration
     • User-defined, and soon, table introspection



Tuesday, October 20, 2009
base is a decorator
     @base
     def db_api(query):
       con = db.connect(conn_string)
       cur = con.cursor()
       return cur(query)




Tuesday, October 20, 2009
Which leads to
     try:
       rs = db_api(‘select * from test_api()’)
     except NotFoundError, e:
       # A hah! A usable error!
       pass




Tuesday, October 20, 2009
As Opposed To
     try:
       rs = db_api(‘select * from test_api()’)
     except InternalError, e:
       if “NotFoundException” in str(e):
          raise NotFoundError(str(e))
       elif “PermissionsError” in str(e):
          raise PermissionsError(str(e))




Tuesday, October 20, 2009
Our Python Example


     • The Exceptable decorator is easy to set up
     • Designed for DB-API integration
     • User-defined, and soon, table introspection
     • Existing decorators can be expanded easily


Tuesday, October 20, 2009
Grow, my Pretties!
     class NotNullError(BaseException):
       pass
     class SCE(BaseException):
       pass

     base.add({
      ‘NotNullException’: NotNullError,
      ‘SufficientCoffeeException’: SCE
     })


Tuesday, October 20, 2009
Permission Denied


     • Exceptable.py also wraps the base permission
           denied

     • DB permissions violations work at the app level



Tuesday, October 20, 2009
Vertically Challenged
     a = c.Function(‘test_auth’);
     try:
       result = a()
     except PermissionDenied, e:
       abort(403)
     except NoSuchUser, e:
       abort(401)




Tuesday, October 20, 2009
AND THUS
                             Questions?




Tuesday, October 20, 2009
Get It!

  https://projects.commandprompt.com/
            public/exceptable/




Tuesday, October 20, 2009
THANK YOU!



Tuesday, October 20, 2009

More Related Content

Viewers also liked (6)

Curso/CTR Reisejournalismus: Berlin
Curso/CTR Reisejournalismus: BerlinCurso/CTR Reisejournalismus: Berlin
Curso/CTR Reisejournalismus: Berlin
 
CTR: My Berlin
CTR: My BerlinCTR: My Berlin
CTR: My Berlin
 
Curso/CTR Reisejournalismus: When in Berlin
Curso/CTR Reisejournalismus: When in BerlinCurso/CTR Reisejournalismus: When in Berlin
Curso/CTR Reisejournalismus: When in Berlin
 
CTR Barcelona: Picture This
CTR Barcelona: Picture ThisCTR Barcelona: Picture This
CTR Barcelona: Picture This
 
Vertically Challenged
Vertically ChallengedVertically Challenged
Vertically Challenged
 
Curso/CTR Reisejournalismus: Start Berlin
Curso/CTR Reisejournalismus: Start BerlinCurso/CTR Reisejournalismus: Start Berlin
Curso/CTR Reisejournalismus: Start Berlin
 

Similar to Exceptable

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2Jazkarta, Inc.
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGuillaume Laforge
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby ConferenceJohn Woodell
 
Testing Zen
Testing ZenTesting Zen
Testing Zenday
 
Treating Infrastructure as Garbage
Treating Infrastructure as GarbageTreating Infrastructure as Garbage
Treating Infrastructure as GarbageDatadog
 
PHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An IntroductionPHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An Introductionalexmace
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009John Woodell
 
Plugin Testing
Plugin TestingPlugin Testing
Plugin TestingTim Moore
 
"How Mozilla Uses Selenium"
"How Mozilla Uses Selenium""How Mozilla Uses Selenium"
"How Mozilla Uses Selenium"Stephen Donner
 
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives: A...
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives:  A...Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives:  A...
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives: A...Day Software
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009Caue Guerra
 
Sharing content between hippo and solr
Sharing content between hippo and solrSharing content between hippo and solr
Sharing content between hippo and solrJettro Coenradie
 

Similar to Exceptable (20)

Howdah
HowdahHowdah
Howdah
 
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Plone on Amazon EC2
Plone on Amazon EC2Plone on Amazon EC2
Plone on Amazon EC2
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Rubypalooza 2009
Rubypalooza 2009Rubypalooza 2009
Rubypalooza 2009
 
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
 
Red Dirt Ruby Conference
Red Dirt Ruby ConferenceRed Dirt Ruby Conference
Red Dirt Ruby Conference
 
Testing Zen
Testing ZenTesting Zen
Testing Zen
 
Don Schwarz App Engine Talk
Don Schwarz App Engine TalkDon Schwarz App Engine Talk
Don Schwarz App Engine Talk
 
Treating Infrastructure as Garbage
Treating Infrastructure as GarbageTreating Infrastructure as Garbage
Treating Infrastructure as Garbage
 
PHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An IntroductionPHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An Introduction
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
 
JRubyConf 2009
JRubyConf 2009JRubyConf 2009
JRubyConf 2009
 
Plugin Testing
Plugin TestingPlugin Testing
Plugin Testing
 
"How Mozilla Uses Selenium"
"How Mozilla Uses Selenium""How Mozilla Uses Selenium"
"How Mozilla Uses Selenium"
 
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives: A...
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives:  A...Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives:  A...
Lowering IT Costs with a Standards-based Platform for Web 2.0 Initiatives: A...
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
 
Sharing content between hippo and solr
Sharing content between hippo and solrSharing content between hippo and solr
Sharing content between hippo and solr
 
Vagrant at LA Ruby
Vagrant at LA RubyVagrant at LA Ruby
Vagrant at LA Ruby
 

Recently uploaded

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Exceptable

  • 2. Exception Propagation, in PostgreSQL and Python Aurynn Shaw, Commandprompt, Inc. PostgreSQL Conference West, 2009 Tuesday, October 20, 2009
  • 3. Background • Large, enterprise Python + Pylons application • Simpycity ORM utilizes significant stored procedures • Strong procedural interfaces Tuesday, October 20, 2009
  • 4. Stored Procedures are Rare • Most people don’t use Stored Procedures. Tuesday, October 20, 2009
  • 5. The Present System Wherein • A Database Query • A Stored Procedure • Or, A Database Query • Exceptions Galore Tuesday, October 20, 2009
  • 6. A Database Query • The App queries the Database Tuesday, October 20, 2009
  • 7. A Database Query • The App queries the Database • Any variety of query Tuesday, October 20, 2009
  • 8. A Database Query >>> c.Raw("SELECT * FROM auth_only")() Traceback (most recent call last): ... <SNIP> ... psycopg2.ProgrammingError: permission denied for relation auth_only Tuesday, October 20, 2009
  • 9. A Database Query • The App queries the Database • Any variety of query • Or A Stored Procedure Tuesday, October 20, 2009
  • 10. Or a Stored Procedure CREATE OR REPLACE FUNCTION except_test() RETURNS VOID AS $$ BEGIN RAISE EXCEPTION 'Test!'; END; $$ LANGUAGE PLPGSQL; >>> c.Function("except_test")() Traceback (most recent call last): ... <SNIP> ... psycopg2.InternalError: Test! Tuesday, October 20, 2009
  • 11. Beget an Exception • Stored procedures raise InternalErrors • Every procedural exception becomes this • Permissions violations raise ProgrammingErrors • I haven’t tested if this is all PG exceptions. Tuesday, October 20, 2009
  • 12. Seriously? • This is what we have to work with? Tuesday, October 20, 2009
  • 13. Why this is Important Wherein • Why? • Defining your APIs • Separation of Concerns • Procedural Spaghetti Tuesday, October 20, 2009
  • 14. Why? • Limited information to propagate upwards • Stored Procedures are Harder to use • Permissions violations are difficult to detect Tuesday, October 20, 2009
  • 15. API Undefined • Exceptions are part of your API Tuesday, October 20, 2009
  • 16. API Undefined • Exceptions are part of your API • Easily overlooked Tuesday, October 20, 2009
  • 17. API Undefined • Exceptions are part of your API • Easily overlooked • Delineations will make life easier Tuesday, October 20, 2009
  • 18. Separation of Concerns • The Database is for Database Logic Tuesday, October 20, 2009
  • 19. Separation of Concerns • The Database is for Database Logic • Harder to write Data Logic Tuesday, October 20, 2009
  • 20. Spaghetti Early version of our app didn’t have Exceptable - we were left catching InternalErrors and guessing at what • InternalErrors everywhere the error was, based on timing. Tuesday, October 20, 2009
  • 21. Spaghetti • InternalErrors everywhere • Insufficiency of Information Tuesday, October 20, 2009
  • 22. Spaghetti • InternalErrors everywhere • Insufficiency of Information • Considerable Repeated Code Tuesday, October 20, 2009
  • 23. A Saving Grace • Violating Procedure Signatures -> Python DataError Tuesday, October 20, 2009
  • 24. A Better Deal Wherein • Database API • Easy Python implementation • Universality • Exceptable Tuesday, October 20, 2009
  • 25. Database API • Easier to define an API Tuesday, October 20, 2009
  • 26. Database API • Easier to define an API • The DB becomes part of that API Tuesday, October 20, 2009
  • 27. Database API • Easier to define an API • The DB becomes part of that API • Simple Stored Procedure interface Tuesday, October 20, 2009
  • 28. Database API • Easier to define an API • The DB becomes part of that API • Simple Stored Procedure interface • Easily declare new Exceptions Tuesday, October 20, 2009
  • 29. Wonderfully Python • A Simple Decorator Tuesday, October 20, 2009
  • 30. Simply Decorated from exceptable.exceptable import Except base = Except() @base def db_function(): pass Tuesday, October 20, 2009
  • 31. Wonderfully Python • A Simple Decorator • Catches and re-emits Exceptions • The core of Exceptable • Easy to Integrate - 2 lines, in Simpycity Tuesday, October 20, 2009
  • 32. Universality • Exceptable Procedures never change • DB logic doesn’t change • Application support is Easy Tuesday, October 20, 2009
  • 33. Exceptable • More Pythonic Database Access • Better exceptions means better app flow Tuesday, October 20, 2009
  • 34. Example Code Wherein • The DB Library • The Application Implementation • Catching Permissions Violations • PostgreSQL 8.4 Tuesday, October 20, 2009
  • 35. To Start, CREATE TABLE exceptions ( name text primary key, description text not null, parent text references exceptions(name) ); INSERT INTO exceptions VALUES ('Exception', 'Base exception',NULL); INSERT INTO exceptions VALUES ('NotFoundException', 'Could not find specified record', 'Exception'); Tuesday, October 20, 2009
  • 36. Which leads to CREATE OR REPLACE FUNCTION not_found ( in_reason TEXT ) RETURNS VOID as $body$ SELECT exceptaple.raise( 'NotFoundException', $1 ); $body$ LANGUAGE SQL; Tuesday, October 20, 2009
  • 37. Application Level • Easy to Query the Exception tables Tuesday, October 20, 2009
  • 38. Application Level • Easy to Query the Exception tables • Easy to set up a new library • Python took 50 lines Tuesday, October 20, 2009
  • 39. Our Python Example • The Exceptable decorator is easy to set up • Designed for DB-API integration Tuesday, October 20, 2009
  • 40. In the Application base = Except(InternalError, { 'Exception': Exception, 'NotFoundException': NotFoundError, }) Tuesday, October 20, 2009
  • 41. Our Python Example • The Exceptable decorator is easy to set up • Designed for DB-API integration • User-defined Tuesday, October 20, 2009
  • 42. User Definitions base = Except(InternalError, { 'PermissionError': PermissionError, 'UnknownUser': UnknownUserError, 'NotFoundException': NotFoundError, }) Tuesday, October 20, 2009
  • 43. Our Python Example • The Exceptable decorator is easy to set up • Designed for DB-API integration • User-defined, and soon, table introspection Tuesday, October 20, 2009
  • 44. base is a decorator @base def db_api(query): con = db.connect(conn_string) cur = con.cursor() return cur(query) Tuesday, October 20, 2009
  • 45. Which leads to try: rs = db_api(‘select * from test_api()’) except NotFoundError, e: # A hah! A usable error! pass Tuesday, October 20, 2009
  • 46. As Opposed To try: rs = db_api(‘select * from test_api()’) except InternalError, e: if “NotFoundException” in str(e): raise NotFoundError(str(e)) elif “PermissionsError” in str(e): raise PermissionsError(str(e)) Tuesday, October 20, 2009
  • 47. Our Python Example • The Exceptable decorator is easy to set up • Designed for DB-API integration • User-defined, and soon, table introspection • Existing decorators can be expanded easily Tuesday, October 20, 2009
  • 48. Grow, my Pretties! class NotNullError(BaseException): pass class SCE(BaseException): pass base.add({ ‘NotNullException’: NotNullError, ‘SufficientCoffeeException’: SCE }) Tuesday, October 20, 2009
  • 49. Permission Denied • Exceptable.py also wraps the base permission denied • DB permissions violations work at the app level Tuesday, October 20, 2009
  • 50. Vertically Challenged a = c.Function(‘test_auth’); try: result = a() except PermissionDenied, e: abort(403) except NoSuchUser, e: abort(401) Tuesday, October 20, 2009
  • 51. AND THUS Questions? Tuesday, October 20, 2009
  • 52. Get It! https://projects.commandprompt.com/ public/exceptable/ Tuesday, October 20, 2009