DetachedInstanceError: dealing with Celery, Flask’s app context and SQLAlchemy

In the open event server project, we had chosen to go with celery for async background tasks. From the official website,

What is celery?

Celery is an asynchronous task queue/job queue based on distributed message passing.

What are tasks?

The execution units, called tasks, are executed concurrently on a single or more worker servers using multiprocessing.

After the tasks had been set up, an error constantly came up whenever a task was called

The error was:

DetachedInstanceError: Instance <User at 0x7f358a4e9550> is not bound to a Session; attribute refresh operation cannot proceed

The above error usually occurs when you try to access the session object after it has been closed. It may have been closed by an explicit session.close() call or after committing the session with session.commit().

The celery tasks in question were performing some database operations. So the first thought was that maybe these operations might be causing the error. To test this theory, the celery task was changed to :

@celery.task(name='lorem.ipsum')
def lorem_ipsum():
    pass

But sadly, the error still remained. This proves that the celery task was just fine and the session was being closed whenever the celery task was called. The method in which the celery task was being called was of the following form:

def restore_session(session_id):
    session = DataGetter.get_session(session_id)
    session.deleted_at = None
    lorem_ipsum.delay()
    save_to_db(session, "Session restored from Trash")
    update_version(session.event_id, False, 'sessions_ver')


In our app, the app_context was not being passed whenever a celery task was initiated. Thus, the celery task, whenever called, closed the previous app_context eventually closing the session along with it. The solution to this error would be to follow the pattern as suggested on http://flask.pocoo.org/docs/0.12/patterns/celery/.

def make_celery(app):
    celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    task_base = celery.Task

    class ContextTask(task_base):
        abstract = True

        def __call__(self, *args, **kwargs):
            if current_app.config['TESTING']:
                with app.test_request_context():
                    return task_base.__call__(self, *args, **kwargs)
            with app.app_context():
                return task_base.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery

celery = make_celery(current_app)


The __call__ method ensures that celery task is provided with proper app context to work with.

 

How to join the FOSSASIA Community

We often get the question, how can I join the community. There is no official membership form to fill out in order to participate in the Open Tech Community. You simply start to contribute and you are already a member. So, let’s work together to develop to develop social software for everyone!

The FOSSASIA team welcomes contributors and supporters to Free and Open Source Software. Become a developer, a documentation writer, packaging maintainer, tester, user supporter, blogger, journalist writing about FOSSASIA or organize events and present Free and Open Source Software projects in Asia.

Women in IT discussion in the community

Here are some ideas how we can collaborate:

Read the blogs and support users in the mailing list

Many FOSS blogs are written by developers, contributors, volunteers, and staff of companies supporting the FOSSASIA network – stay up on free software related progress and news and start to get involved. Sign up for the FOSSASIA Mailing List http://groups.google.com/group/fossasia and keep reading our Blog at: http://blog.fossasia.org

FOSSASIA Twitter

Follow FOSSASIA on Twitter and retweet important updates: https://twitter.com/fossasia

FOSSASIA at Google+ and Facebook

Become a member on social networks:

* https://plus.google.com/108920596016838318216
* http://www.facebook.com/fossasia/

Add your community in Asia to the FOSSASIA community network list

FOSSASIA is connecting communities throughout Asia and around the world. Please add communities in Asia to the community network list here: github.com/fossasia/fossasia-communities

Support the FOSSASIA network at Community Events

Set up a booth or a table about FOSSASIA at open source community events! There are many events of the open source community all over the world. The core team of FOSSASIA is simply not able to attend all events. You can support the cause by making the project visible. Register as a member of the FOSSASIA community at events, set up an info point and showcase Free and Open Source projects. Check out for example our meetup group in Singapore: meetup.com/FOSSASIA-Singapore-Open-Technology-Meetup/

Download Open Source Software from the FOSSASIA Github repo, join as a developer or tester:

The first step of joining a project is always to download the software and try it out: http://github.com/fossasia and our project for big data: http://github.com/loklak

Translate FOSS projects and their documentation

Do you speak more than one language? Most FOSS projects are 100% volunteer translated, which means you can be part of a translation team translating software and documentation thousands of people will use. The point to start is also our GitHub repo.

Mini Debconf Participants in Saigon

FOSSASIA Open Technology Summit 2015 in Singapore

Singapore, March 8, 2015 – FOSSASIA will take place in Singapore for the first time this year. The conference will feature over 100 talks and workshops covering the latest in Free and Open Source Technology projects, including those focused on the development of Singapore as a smart nation.

The summit is hosted by NUS Enterprise, ACE, Silicon Straits, JFDI and SingTel Innov8 in partnership with IDA, Red Hat, Google, Oracle, MySQL, Mozilla Foundation, Python Foundation, Treasure Data, MBM Asia, Uptime and many more. The event will kick off on Friday at Biopolis and continue on Saturday and Sunday at JTC LaunchPad @ one-north.

The organizers are particularly excited to welcome keynote speakers including Colin Charles from MariaDB running Wikipedia one of the biggest websites in the world, Italo Vignoli – co-founder of LibreOffice, Bunnie Huang – the founder of the Novena laptop project, Stefan Koehler – lead engineer of the City of Munich’s whole-of-government Linux project LiMux, and Georg C. F. Greve – the founder of Free Software Foundation Europe.

Mario Behling, head of Program Planning, said “This year we are welcoming over 120 speakers from 26 countries, making this both the largest and most diverse FOSSASIA speaker roster ever. Of particular interest is the increasing presence of open hardware, which is important for Singapore as the growth in open hardware development combined with proximity to Asian manufacturing capacity and commitment to building a Smart Nation creates a wealth of opportunities for innovation.”

Other topics and activities include: Free and Open Source software, web and mobile development, software for education, map solutions for websites and phones, open knowledge tools, Wikipedia, open data, big data, sensor networks, free wireless networks, graphic design, fashion technology, open source knitting machines, 3D printing, key signing parties to help local developers join the PGP web of trust and the opportunity for participants to obtain their Linux Foundation Certification organised by the Linux Foundation in cooperation with OlinData.

Agenda

Day 1, Fri.13 Mar,  9am – 5pm: Opening Event at Biopolis with IDA, Red Hat, Google, Mozilla

Day 2, Sat.14 Mar, 9am – 5pm: Talks and presentations of developers and designers at LaunchPad @ one-north

Day 3, Sun.15 Mar, 10am – 4.30 pm: Hands-on seminars and workshops at LaunchPad

Links

FOSSASIA: fossasia.org

Summit Site: 2015.fossasia.org

Let’s build an Open Textile and Garment Production Line – Talk at the 31c3 Congress Hamburg

Here is my talk at the 31c3 Chaos Communication Congress about FashionTec projects and Open Garment Production Lines. Hope you enjoy it.

Links

Hong Phuc Dang at the 31c3 Chaos Communication Congress

Let’s build our own personalized open textile production line

Community Networks and Freifunk: Help to translate

Community networks extend the model of Open Source to networks and enable people to share services and Internet connections locally. I translated a video of the Freifunk community to Vietnamese. Versions in different languages are available. Join us and translate the video! The translation pad is here http://pad.freifunk.net/p/Spot2013

 

Links:

Freifunk: http://blog.freifunk.net

OpenWrt: http://openwrt.org

Hackerspace Singapore Vietnamese Tech Scene Meetup

Thanks to all you folks who came by and Thank you for Preetam on posting some nice comments and photos about the event. And last but not least, thank you to the great hosts from the Hackerspace.sg.

“One point they made strongly was that having a local partner would ease a lot of pain, right from registering your company to collecting market data. Hong Phuc talked about her method of working with local universities and government agencies to gather customer data.”

 

Join us at Hackerspace.sg

Vietnam has one of the fastest growing online population in the region, probably globally too. Vietnam is also seeing growth in IT companies exploring the local market and setting up offshoring centers.

Vietnam-based entrepreneurs and FOSSASIA event organizers Dang Hong Phuc and Mario Behling are visiting Singapore and will be talking about the startup and tech scene in VN and what opportunities there might be for collaboration (tech events, open source, women in IT etc.).

Event Details
When: Thursday 3rd March 2011
Time: 7pm
Where: Hackerspace.sg, 70A Bussorah Lane

Open Design Weeks 2011 Saigon

The Open Design Weeks Asia take place in Hochi Minh City and Cantho (Vietnam) from April 2-16, 2011. The program has been announced. There will be an Open Design Camp in Saigon and intensive workshops in Cantho.

The focus of the Open Design Weeks are on design, Free, Libre and Open Source software, open content and Free Culture practices. Events during the design weeks include workshops, design camps to share expertise an unconference, company meet ups to establish international cooperations, presentations in Universities and training workshops. The intensive workshops with local designers, software developers and typographers focus on collaborative font design, mapping and publication.

This will be a great chance to get involved in some new and exciting projects

Open Design Weeks: http://opendesign.asia

FOSSASIA 2010: Bridge to Asia

FOSSASIA 2010 took place at the Raffles College campus in Ho Chi Minh City (Saigon), Vietnam from November 12th to 14th. This inaugural event brought together over 350 international and local developers and users in 62 presentations and panels. An amazing crowd of 90 enthusiastic volunteers supported participants. FOSSASIA attendees came from 30 countries including Cambodia, Singapore, Indonesia, Japan, India, Taiwan, Malaysia, Germany, France, England, Australia, and the US.

The goal of FOSSASIA is to provide knowledge of free and open source software and to offer the community a place to meet and share ideas. The annual conference brings together members of the Asian FOSS community along with the international community, thus fostering cooperation across projects and across borders.

Special Tracks: Women in IT and Lightweight Computing

The 2010 event offered 5 tracks including the two special theme tracks “Women in IT” and “Lightweight Computing”.

Hong Phuc Dang from MBM Vietnam said of the Women in IT panel:

“It is fascinating to see so many girls participating. I am very happy that we have chosen ‘Women in IT’ as a theme as it attracted many students to join us.”

Other participants of the women panel were Lilly Nguyen (UCLA, US), Van Thi Bich Ty (PCWorld, Vietnam), Mary Agnes James (Seacem), Lita Cheng (Community Cambodia) and Kounila Keo (ICT4D Cambodia).

The heated debate during the panel definitely portrayed some of the issues and challenges young female developers face. I hope that it made many of the younger women more interested in participating in the community. I am excited to see more involvement of women in IT in Asia in the near future” said Lilly Nguyen from the US.

The “Lightweight Computing” track also generated a lot of interest. Lubuntu, the lightweight version of Ubuntu, attracted the attention of local developers. Additionally, mobile solutions such as Android and Xpad/Xpud were covered in several presentations by Ping-Hsun Chen (Taiwan), Pham Huu Ngon (Vietnam) and Tan Quang Sang (Vietnam).

OpenOffice.org Asia Meet Up

FOSSASIA was particularly happy to welcome the OpenOffice.org community who sponsored the event. As head of the Vietnamese OOo localization team, Vu Do Quynh from Hanoilug presented on the various ways that people could contribute to the OOo community while Yutaka Niibe and Yukiharu Yabuki presented on OOo’s use by the Japenese government in the Osaka Prefecture.

Mini-Debconf, Fedora Release Party and Mozilla

FOSSASIA 2010 was also an opportunity for the Debian community to organize a Mini-Debconf. Debian developers present included among others Jonas Smedegaard (Denmark), Paul Wise (Australia) and Thomas Goirand (France/China).

To celebrate the release of Fedora 14, Ambassador Anh Tuan Truong (Vietnam) and Pierros Papadeas (Greece) hosted the world’s largest release party. The even took place at the Ho Chi Minh City University of Pedagogy. Pierros–an active Mozilla contributor—had  this to say about the release event:

“It was AWESOME. At first I thought most of them were there due to their teachers, but  when we started a Q&A session I realized I was so wrong… they were  asking about PAE kernels, broadcom drivers, dual boot and LVM etc! By the end of the party we gave out T-shirts, LiveCDs and stickers to everyone, all 134 people where there! I believe that sets a new fedora record! The local Vietnamese community was introduced and many people are already starting to send emails wanting to start translating.”

The FOSS Bridge to Asia

Projects also used the event as an opportunity to showcase new tools and devices like the Freedombox project of the Freifunk community and the latest version of the Crypto-Stick. Jan Suhr (Germany/Singapore) showed the device as a combination of both open hardware and open software.

In the web track, Colin Charles (Malaysia) presented the newest improvements of MariaDB. In addition, Michael Howden (New Zealand) conducted a workshop for Sahan Eden, a platform to provide support in the case of disasters. The workshop gave students a chance understand the information needs of disaster scenarios and they were able to contribute to the localization of the software.

Several web content management systems set-up information booths at the event. These included: TYPO3 with a booth organized by Dominik Stankowski from Web Essentials Cambodia and Drupal (Virak Hor, Cambodia and Quang Thong Tran, Vietnam). The event also introduced other tools such as Zabbix, a monitoring software (Walter Heck, Netherlands). One more hot topic was the enterprise p2p search engine YaCy.net of Michael Christen (Germany). A number of more established projects had the opportunity to share their news at the event including the desktop environments KDE with a presentation about Qt (Gregory Schlomoff, France), GNOME (Kien Truc Le, Vietnam), and LXDE (Duy Hung Tran, Vietnam).

Unconference

Taking a cue from previous barcamps and ‘unconferences,’ many attendees presented lightning talks. Preetam Rai, an Android App inventor, shared photos and tales about other barcamps throughout Southeast Asia. Mary Agnes James from Seacem spoke about todays chances to connect and share with e-media and social networks. Seacem also graciously sponsored this event.

Libre Graphics and Open Design

During the final day of the event, FOSSASIA held it’s first Libre Graphics Day. Arne Goetje (Germany/Taiwan) introduced his new approach for a pan-Asian fonts library. Jon Philips (US) from Status.net and Dave Crossland (UK) from the Google Fonts project conducted an Open Design Workshop. The workshops brought curious crowds and has ultimately seeded plans for the Open Design Weeks 2011.

See you in Vietnam

Thanks again to the amazing crowd at FOSSASIA – developers, translators, event organizers, bloggers, teachers, students, designers and lost but not least our enthusiastic volunteers! See you all in 2011!

* FOSSASIA 2011 will take place in Ho Chi Minh City (Saigon) on November 11-12
* The Open Design Weeks 2011 will be celebrated from April 2-15 in Ho Chi Minh City and Can Tho in the Mekong Delta.

Links:

* FOSSASIA http://fossasia.org
* Open Design Weeks Asia, http://opendesign.asia

How to get contributors from Asia for your Open Source project – Talk at Libre Graphics Meeting Brussels

I had the chance to talk about the topic of how to get contributors for Free/Libre/Open Source projects from Vietnam and Asia at the Libre Graphics Meeting Brussels. It was a a fantastic experience to meet developers and contributors from all over the world and I hope to support projects with the insights of this talk.

The situation in 2010 in Asia is, that many people still do not know about Free and Open Source. We need more people to support each other and help new users und developers. We need more developers in Vietnam to adapt existing solutions for Vietnamese and Asian users. We need people to organize events, where we can meet face to face. We need mentors, who developers and contributors can turn to. We need business people who understand business models and opportunities around Free and Open Source. We need you! FOSS can be a sustainable model for Vietnam as it is for other countries. Please join us in our effort for education, spreading knowledge, developement of better, faster and energy-saving software, designing easy to use interfaces and promoting opportunities for everyone with Free and Open Source.

Links

* Libre Graphics Meeting 2010: http://libregraphicsmeeting.org/2010

* LGM: http://libregraphicsmeeting.org