Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:43:16+00:00 2026-05-28T15:43:16+00:00

When I make a raw SQL query in Django, some queries get _ip.magic into

  • 0

When I make a raw SQL query in Django, some queries get _ip.magic into the string, and then string formatting raises exceptions since there are not enough or too many parameters.

Sample code was reduced to the minimum set, but still produces “magics”:

> ids = (1, 4)
> curr = 3
> q = User.objects.raw(u"""
                SELECT
    1
                WHERE
                     a=%s and b=%s AND a.user_id = %s
    """, params=(ids, ids, curr))

> print q.query.sql
... a = _ip.magic("s and b=%s AND a.user_id = %s")

(I don’t mean to run this query, just want to successfully generate a SQL.)

Why is _ip.magic there? Depending on the queries, sometimes it wraps a single parameter, sometimes several of them. How to get rid of it?

edit: the solution was to turn off automagic:

>>> _ip.options['automagic'] = 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:43:17+00:00Added an answer on May 28, 2026 at 3:43 pm

    _ip.magic is as far as I can tell an IPython function and has nothing to do with django itself.

    Try running this code in the plain vanilla django shell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make one query, to get some statistic data from database.
I decided I'd like to use django's model system rather than coding raw SQL
My Requirement is to write a sql query to get the sub-region wise (fault)events
How do python raw strings and string literals work? I'm trying to make a
I am looking to make a query that selects between dates with Django. I
I have a raw buffer with it i need to make 3 others, the
To make it short: hibernate doesn't support projections and query by example? I found
To make click-able divs, I do: <div class=clickable url=http://google.com> blah blah </div> and then
Django seems to be falsely claiming that I have an error in my SQL
I have a SQL Server query that I need to convert to MySQL. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.